[Django]-Django makemessages ignore switch doesn't work for me

35πŸ‘

βœ…

./manage.py help makemessages

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

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

./manage.py makemessages -l da -i β€œdjango*”

But beware that 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 execution.

πŸ‘€benjaoming

2πŸ‘

The problem is with the pattern – maybe the shell was expanding it for you.

In general – it is good to avoid path separators (whether / or \) in the pattern.

If you need to always pass specific options to the makemessages command, you could consider your own wrapper, like this one, 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 you typing, and gives a common entry point for scanning messages across the project (your translator colleague will not destroy translations by missing out some parameter).

Don’t delete the old .po file, once you have cleared it from the totally unwanted (i.e. – those from β€˜django’ directory) messages. This allows gettext to recycle old unused messages, once they are used again (or simmilar ones, which will be marked as #, fuzzy.

Edit – as mt4x noted – the wrapper above doesn’t allow for passing the options to the wrapped command. This is easy to fix:

from django.core.management import call_command
from django.core.management.commands.makemessages import (
    Command as MakeMessagesCommand
)

class Command(MakeMessagesCommand):
    help = "Scan i18n messages without going into externals."
    
    def handle(self, *args, **options):
        options['all'] = True
        options['extensions'] = ['html', 'inc']

        if 'ignore_patterns' not in options:
            options['ignore_patterns'] = []

        options['ignore_patterns'] += ['externals*']
        call_command('makemessages', **options)

Thus – you can fix what needs to be fixed, and flex the rest.
And this needs not be blind override like above, but also some conditional edit of the parameters passed to the command – appending something to a list or only adding it when it’s missing.

πŸ‘€Tomasz Gandor

Leave a comment