Ticket #10004: makemessages.py.diff

File makemessages.py.diff, 4.1 KB (added by martinb, 14 years ago)

Patch for makemessages.py: Call xgettext with -c/--add-comments

  • makemessages.py

    old new  
    4242    p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, close_fds=os.name != 'nt', universal_newlines=True)
    4343    return p.communicate()
    4444
    45 def make_messages(locale=None, domain='django', verbosity='1', all=False, extensions=None):
     45def make_messages(locale=None, domain='django', verbosity='1', all=False, extensions=None, addcomments=False):
    4646    """
    4747    Uses the locale directory from the Django SVN tree or an application/
    4848    project to process all
     
    106106        for (dirpath, dirnames, filenames) in os.walk("."):
    107107            all_files.extend([(dirpath, f) for f in filenames])
    108108        all_files.sort()
     109        addcomments_switch = ''
     110        if addcomments == '':
     111            addcomments_switch = '--add-comments'
     112        elif addcomments and len(addcomments) > 0:
     113            addcomments_switch = '--addcomments=%s' % addcomments
    109114        for dirpath, file in all_files:
    110115            file_base, file_ext = os.path.splitext(file)
    111116            if domain == 'djangojs' and file_ext == '.js':
     
    115120                src = pythonize_re.sub('\n#', src)
    116121                thefile = '%s.py' % file
    117122                open(os.path.join(dirpath, thefile), "w").write(src)
    118                 cmd = 'xgettext -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (domain, os.path.join(dirpath, thefile))
     123                cmd = 'xgettext -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 %s -o - "%s"' % (domain, addcomments_switch, os.path.join(dirpath, thefile))
    119124                msgs, errors = _popen(cmd)
    120125                if errors:
    121126                    raise CommandError("errors happened while running xgettext on %s\n%s" % (file, errors))
     
    142147                        raise SyntaxError(msg)
    143148                if verbosity > 1:
    144149                    sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
    145                 cmd = 'xgettext -d %s -L Python --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --keyword=ugettext_noop --keyword=ugettext_lazy --keyword=ungettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (
    146                     domain, os.path.join(dirpath, thefile))
     150                cmd = 'xgettext -d %s -L Python --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --keyword=ugettext_noop --keyword=ugettext_lazy --keyword=ungettext_lazy:1,2 --from-code UTF-8 %s -o - "%s"' % (
     151                    domain, addcomments_switch, os.path.join(dirpath, thefile))
    147152                msgs, errors = _popen(cmd)
    148153                if errors:
    149154                    raise CommandError("errors happened while running xgettext on %s\n%s" % (file, errors))
     
    186191        make_option('--extension', '-e', dest='extensions',
    187192            help='The file extension(s) to examine (default: ".html", separate multiple extensions with commas, or use -e multiple times)',
    188193            action='append'),
     194        make_option('--add-comments', '-c', dest='addcomments',
     195            help='place comment block with TAG (or those preceding keyword lines) in output file',
     196            default=False),
    189197    )
    190198    help = "Runs over the entire source tree of the current directory and pulls out all strings marked for translation. It creates (or updates) a message file in the conf/locale (in the django tree) or locale (for project and application) directory."
    191199
     
    201209        verbosity = int(options.get('verbosity'))
    202210        process_all = options.get('all')
    203211        extensions = options.get('extensions') or ['html']
     212        addcomments = options.get('addcomments')
    204213
    205214        if domain == 'djangojs':
    206215            extensions = []
     
    210219        if '.js' in extensions:
    211220            raise CommandError("JavaScript files should be examined by using the special 'djangojs' domain only.")
    212221
    213         make_messages(locale, domain, verbosity, process_all, extensions)
     222        make_messages(locale, domain, verbosity, process_all, extensions, addcomments)
Back to Top