Django makemessages ignore switch not working for me

I am having problems localizing a django-nonrel project that is being deployed to GAE. Due to GAE, I have to put everything in the project folder, so it looks something like this.

project + django + dbindexer + registration + myapp ... + locale + templates 

I have lines for localization in the templates directory and in the myapp . When I run python manage.py makemessages -l en --ignore django\* from the dir project, it scans through all the project directories, including django, so I get a fairly large po file. My strings from templates exist along with all the strings from the django directory.

after --ignore (or just -i) I tried pu django django/* but nothing changed. Any ideas?

+6
source share
2 answers

./manage.py help makemessages

 -i PATTERN, --ignore=PATTERN Ignore files or directories matching this glob-style pattern. Use multiple times to ignore more. 

I just tested it and this command successfully ignored my application:

./manage.py makemessages -l da -i "django *"

But be careful, before you test it, you should delete the old .po file, as I think it will not automatically remove the translation lines from your previous makemessages run.

+14
source

The problem is with the template - perhaps the shell has expanded it for you.

In general, it is useful to avoid path separators (or / or \) in the template.

If you need to always pass certain parameters to the makemessages , you can consider your own wrapper, such as this, which I use myself:

 from django.conf import settings from django.core.management.base import BaseCommand from django.core.management import call_command class Command(BaseCommand): help = "Scan i18n messages without going into externals." def handle(self, *args, **options): call_command('makemessages', all=True, extensions=['html', 'inc'], ignore_patterns=['externals*']) 

This saves your writing and provides a common entry point for scanning messages on the project (your translation colleague will not destroy translations without specifying any parameter).

Do not delete the old .po file as soon as you have cleaned it of completely unwanted ones (that is, from the django directory). This allows gettext to process old unused messages as soon as they are used again (or similar, which will be marked as #, fuzzy .

Change - as mt4x noted - the above shell does not allow passing parameters to the wrapped command. This is easy to fix:

 from django.conf import settings from django.core.management.base import BaseCommand from django.core.management import call_command from django.core.management.commands.makemessages import Command as MakeMessagesCommand class Command(BaseCommand): help = "Scan i18n messages without going into externals." option_list = MakeMessagesCommand.option_list def handle(self, *args, **options): options['all'] = True options['extensions'] = ['html', 'inc'] options['ignore_patterns'] = ['externals*'] call_command('makemessages', **options) 

That way - you can fix what needs to be fixed and bend the rest. And this should not be blind, as described above, but also conditional editing of the parameters passed to the command - adding something to the list or adding it only if it is absent.

+2
source

Source: https://habr.com/ru/post/898169/


All Articles