zhongrj
2025-11-25 b89962006164a462404b79a738bee8cbb6d7fe7e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from django.core.management.commands.makemessages import Command as MMCommand
 
# https://medium.com/@hugosousa/hacking-djangos-makemessages-for-better-translations-matching-in-jsx-components-1174b57a13b1
class Command(MMCommand):
    """
    This is a wrapper for the makemessages command and
    it is used to force makemessages call xgettext with the language
    provided as input
    The solution is really hacky and takes advantage of the fact
    that in makemessages TranslatableFile process()
    the options in command.xgettext_options are appended to the end
    of the xgettext command.
    """
    def add_arguments(self, parser):
        parser.add_argument(
            '--language',
            '-lang',
            default='Python',
            dest='language',
            help='Language to be used by xgettext'
        )
    
        super(Command, self).add_arguments(parser)
    def handle(self, *args, **options):
        language = options.get('language')
        self.xgettext_options.append('--language={lang}'.format(
            lang=language
        ))
        super(Command, self).handle(*args, **options)