Ticket #13936: makemessages.py.diff

File makemessages.py.diff, 5.6 KB (added by Cristian Ciupitu, 14 years ago)

Patch for "makemessages.py"

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

    diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py
    index 955a822..21d6d0b 100644
    a b def handle_extensions(extensions=('html',)):  
    3838    # trick xgettext to parse them as Python files)
    3939    return set([x for x in ext_list if x != '.py'])
    4040
    41 def _popen(cmd):
     41def _popen(cmd, cwd=None):
    4242    """
    4343    Friendly wrapper around Popen for Windows
    4444    """
    45     p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, close_fds=os.name != 'nt', universal_newlines=True)
     45    p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, close_fds=os.name != 'nt', universal_newlines=True, cwd=cwd)
    4646    return p.communicate()
    4747
    4848def walk(root, topdown=True, onerror=None, followlinks=False):
    def make_messages(locale=None, domain='django', verbosity='1', all=False,  
    133133    if os.path.isdir(os.path.join('conf', 'locale')):
    134134        localedir = os.path.abspath(os.path.join('conf', 'locale'))
    135135        invoked_for_django = True
     136        relpath = os.path.join(os.path.pardir, os.path.dir)
    136137    elif os.path.isdir('locale'):
    137138        localedir = os.path.abspath('locale')
     139        relpath = os.path.pardir
    138140    else:
    139141        raise CommandError("This script should be run from the Django SVN tree or your project or app tree. If you did indeed run it from the SVN checkout or your project or application, maybe you are just missing the conf/locale (in the django tree) or locale (for project and application) directory? It is not created automatically, you have to create it by hand if you want to enable i18n for your project or application.")
    140142
    def make_messages(locale=None, domain='django', verbosity='1', all=False,  
    168170        if verbosity > 0:
    169171            print "processing language", locale
    170172        basedir = os.path.join(localedir, locale, 'LC_MESSAGES')
     173        # relative path from the PO file to the root of the application/project
     174        relpath = os.path.join(relpath, os.path.pardir, os.path.pardir)
    171175        if not os.path.isdir(basedir):
    172176            os.makedirs(basedir)
    173177
    def make_messages(locale=None, domain='django', verbosity='1', all=False,  
    190194                    f.write(src)
    191195                finally:
    192196                    f.close()
    193                 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))
    194                 msgs, errors = _popen(cmd)
     197                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.normpath(os.path.join(relpath, dirpath, thefile)))
     198                msgs, errors = _popen(cmd, cwd=basedir)
    195199                if errors:
    196200                    raise CommandError("errors happened while running xgettext on %s\n%s" % (file, errors))
    197                 old = '#: '+os.path.join(dirpath, thefile)[2:]
    198                 new = '#: '+os.path.join(dirpath, file)[2:]
     201                old = '#: '+os.path.join(relpath, dirpath[2:], thefile)
     202                new = '#: '+os.path.join(relpath, dirpath[2:], file)
    199203                msgs = msgs.replace(old, new)
    200204                if os.path.exists(potfile):
    201205                    # Strip the header
    def make_messages(locale=None, domain='django', verbosity='1', all=False,  
    226230                if verbosity > 1:
    227231                    sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
    228232                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"' % (
    229                     domain, os.path.join(dirpath, thefile))
    230                 msgs, errors = _popen(cmd)
     233                    domain, os.path.normpath(os.path.join(relpath, dirpath, thefile)))
     234                msgs, errors = _popen(cmd, cwd=basedir)
    231235                if errors:
    232236                    raise CommandError("errors happened while running xgettext on %s\n%s" % (file, errors))
    233237
    234238                if thefile != file:
    235                     old = '#: '+os.path.join(dirpath, thefile)[2:]
    236                     new = '#: '+os.path.join(dirpath, file)[2:]
     239                    old = '#: '+os.path.join(relpath, dirpath[2:], thefile)
     240                    new = '#: '+os.path.join(relpath, dirpath[2:], file)
    237241                    msgs = msgs.replace(old, new)
    238242                if os.path.exists(potfile):
    239243                    # Strip the header
    def make_messages(locale=None, domain='django', verbosity='1', all=False,  
    250254                    os.unlink(os.path.join(dirpath, thefile))
    251255
    252256        if os.path.exists(potfile):
    253             msgs, errors = _popen('msguniq --to-code=utf-8 "%s"' % potfile)
     257            msgs, errors = _popen('msguniq --to-code=utf-8 "%s"' % potfile, cwd=basedir)
    254258            if errors:
    255259                raise CommandError("errors happened while running msguniq\n%s" % errors)
    256260            f = open(potfile, 'w')
    def make_messages(locale=None, domain='django', verbosity='1', all=False,  
    259263            finally:
    260264                f.close()
    261265            if os.path.exists(pofile):
    262                 msgs, errors = _popen('msgmerge -q "%s" "%s"' % (pofile, potfile))
     266                msgs, errors = _popen('msgmerge -q "%s" "%s"' % (pofile, potfile), cwd=basedir)
    263267                if errors:
    264268                    raise CommandError("errors happened while running msgmerge\n%s" % errors)
    265269            elif not invoked_for_django:
Back to Top