Ticket #17008: patch.diff

File patch.diff, 4.9 KB (added by airstrike, 4 years ago)

Adds --keep-pot option to makemessages.py

  • django/core/management/commands/makemessages.py

    commit 104d80fbe490747ea9f410fc76a5e720cb7e6669
    Author: Andre Terra <acterra@timbrasil.com.br>
    Date:   Thu Oct 6 15:17:35 2011 -0300
    
        Added a --keep-pot option to makemessages to ease debugging.
    
    diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py
    index 2c6e171..42929d6 100755
    a b def copy_plural_forms(msgs, locale, domain, verbosity): 
    115115
    116116def make_messages(locale=None, domain='django', verbosity='1', all=False,
    117117        extensions=None, symlinks=False, ignore_patterns=[], no_wrap=False,
    118         no_obsolete=False):
     118        no_obsolete=False, keep_pot=False):
    119119    """
    120120    Uses the locale directory from the Django SVN tree or an application/
    121121    project to process all
    def make_messages(locale=None, domain='django', verbosity='1', all=False, 
    163163        languages = [os.path.basename(l) for l in locale_dirs]
    164164
    165165    wrap = no_wrap and '--no-wrap' or ''
     166    unlink_potfile = lambda potfile: None if keep_pot else os.unlink(potfile)
    166167
    167168    for locale in languages:
    168169        if verbosity > 0:
    def make_messages(locale=None, domain='django', verbosity='1', all=False, 
    201202                msgs, errors = _popen(cmd)
    202203                if errors:
    203204                    os.unlink(os.path.join(dirpath, thefile))
    204                     if os.path.exists(potfile):
     205                    if os.path.exists(potfile) and not keep_pot:
    205206                        os.unlink(potfile)
    206207                    raise CommandError(
    207208                        "errors happened while running xgettext on %s\n%s" %
    def make_messages(locale=None, domain='django', verbosity='1', all=False, 
    248249                if errors:
    249250                    if thefile != file:
    250251                        os.unlink(os.path.join(dirpath, thefile))
    251                     if os.path.exists(potfile):
     252                    if os.path.exists(potfile) and not keep_pot:
    252253                        os.unlink(potfile)
    253254                    raise CommandError(
    254255                        "errors happened while running xgettext on %s\n%s" %
    def make_messages(locale=None, domain='django', verbosity='1', all=False, 
    275276            msgs, errors = _popen('msguniq %s --to-code=utf-8 "%s"' %
    276277                                  (wrap, potfile))
    277278            if errors:
    278                 os.unlink(potfile)
     279                unlink_potfile(potfile)
    279280                raise CommandError(
    280281                    "errors happened while running msguniq\n%s" % errors)
    281282            if os.path.exists(pofile):
    def make_messages(locale=None, domain='django', verbosity='1', all=False, 
    287288                msgs, errors = _popen('msgmerge %s -q "%s" "%s"' %
    288289                                      (wrap, pofile, potfile))
    289290                if errors:
    290                     os.unlink(potfile)
     291                    unlink_potfile(potfile)
    291292                    raise CommandError(
    292293                        "errors happened while running msgmerge\n%s" % errors)
    293294            elif not invoked_for_django:
    def make_messages(locale=None, domain='django', verbosity='1', all=False, 
    299300                f.write(msgs)
    300301            finally:
    301302                f.close()
    302             os.unlink(potfile)
     303            unlink_potfile(potfile)
    303304            if no_obsolete:
    304305                msgs, errors = _popen('msgattrib %s -o "%s" --no-obsolete "%s"' %
    305306                                      (wrap, pofile, pofile))
    class Command(NoArgsCommand): 
    329330            default=False, help="Don't break long message lines into several lines"),
    330331        make_option('--no-obsolete', action='store_true', dest='no_obsolete',
    331332            default=False, help="Remove obsolete message strings"),
     333        make_option('--keep-pot', action='store_true', dest='keep_pot',
     334            default=False, help="Keep .pot file after making messages. Useful when debugging."),
     335
    332336    )
    333337    help = ( "Runs over the entire source tree of the current directory and "
    334338"pulls out all strings marked for translation. It creates (or updates) a message "
    class Command(NoArgsCommand): 
    352356        ignore_patterns = list(set(ignore_patterns))
    353357        no_wrap = options.get('no_wrap')
    354358        no_obsolete = options.get('no_obsolete')
     359        keep_pot = options.get('keep_pot')
    355360        if domain == 'djangojs':
    356361            extensions = handle_extensions(extensions or ['js'])
    357362        else:
    class Command(NoArgsCommand): 
    361366            sys.stdout.write('examining files with the extensions: %s\n'
    362367                             % get_text_list(list(extensions), 'and'))
    363368
    364         make_messages(locale, domain, verbosity, process_all, extensions, symlinks, ignore_patterns, no_wrap, no_obsolete)
     369        make_messages(locale, domain, verbosity, process_all, extensions, symlinks, ignore_patterns, no_wrap, no_obsolete, keep_pot)
Back to Top