Django

Code

Changeset 6445

Show
Ignore:
Timestamp:
10/02/07 20:41:04 (1 year ago)
Author:
mtredinnick
Message:

Fixed #5491 -- Changed PO file generation to sort the filenames we scan prior
to passing them to gettext. This should help reduce the changes in line
orderings caused by different translators using different operating systems and
locales. Based on a patch from Ramiro Morales.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/bin/make-messages.py

    r5842 r6445  
    7575            os.unlink(potfile) 
    7676 
     77        all_files = [] 
    7778        for (dirpath, dirnames, filenames) in os.walk("."): 
    78             for file in filenames: 
    79                 if domain == 'djangojs' and file.endswith('.js'): 
    80                     if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) 
     79            all_files.extend([(dirpath, f) for f in filenames]) 
     80        all_files.sort() 
     81        for dirpath, file in all_files: 
     82            if domain == 'djangojs' and file.endswith('.js'): 
     83                if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) 
     84                src = open(os.path.join(dirpath, file), "rb").read() 
     85                src = pythonize_re.sub('\n#', src) 
     86                open(os.path.join(dirpath, '%s.py' % file), "wb").write(src) 
     87                thefile = '%s.py' % file 
     88                cmd = 'xgettext %s -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % ( 
     89                    os.path.exists(potfile) and '--omit-header' or '', domain, os.path.join(dirpath, thefile)) 
     90                (stdin, stdout, stderr) = os.popen3(cmd, 't') 
     91                msgs = stdout.read() 
     92                errors = stderr.read() 
     93                if errors: 
     94                    print "errors happened while running xgettext on %s" % file 
     95                    print errors 
     96                    sys.exit(8) 
     97                old = '#: '+os.path.join(dirpath, thefile)[2:] 
     98                new = '#: '+os.path.join(dirpath, file)[2:] 
     99                msgs = msgs.replace(old, new) 
     100                if msgs: 
     101                    open(potfile, 'ab').write(msgs) 
     102                os.unlink(os.path.join(dirpath, thefile)) 
     103            elif domain == 'django' and (file.endswith('.py') or file.endswith('.html')): 
     104                thefile = file 
     105                if file.endswith('.html'): 
    81106                    src = open(os.path.join(dirpath, file), "rb").read() 
    82                     src = pythonize_re.sub('\n#', src) 
    83                     open(os.path.join(dirpath, '%s.py' % file), "wb").write(src) 
    84107                    thefile = '%s.py' % file 
    85                     cmd = 'xgettext %s -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % ( 
    86                         os.path.exists(potfile) and '--omit-header' or '', domain, os.path.join(dirpath, thefile)) 
    87                     (stdin, stdout, stderr) = os.popen3(cmd, 't') 
    88                     msgs = stdout.read() 
    89                     errors = stderr.read() 
    90                     if errors: 
    91                         print "errors happened while running xgettext on %s" % file 
    92                         print errors 
    93                         sys.exit(8) 
     108                    open(os.path.join(dirpath, thefile), "wb").write(templatize(src)) 
     109                if verbose: 
     110                    sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) 
     111                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"' % ( 
     112                    domain, os.path.join(dirpath, thefile)) 
     113                (stdin, stdout, stderr) = os.popen3(cmd, 't') 
     114                msgs = stdout.read() 
     115                errors = stderr.read() 
     116                if errors: 
     117                    print "errors happened while running xgettext on %s" % file 
     118                    print errors 
     119                    sys.exit(8) 
     120                if thefile != file: 
    94121                    old = '#: '+os.path.join(dirpath, thefile)[2:] 
    95122                    new = '#: '+os.path.join(dirpath, file)[2:] 
    96123                    msgs = msgs.replace(old, new) 
    97                     if msgs: 
    98                         open(potfile, 'ab').write(msgs) 
     124                if os.path.exists(potfile): 
     125                    # Strip the header 
     126                    msgs = '\n'.join(dropwhile(len, msgs.split('\n'))) 
     127                else: 
     128                    msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8') 
     129                if msgs: 
     130                    open(potfile, 'ab').write(msgs) 
     131                if thefile != file: 
    99132                    os.unlink(os.path.join(dirpath, thefile)) 
    100                 elif domain == 'django' and (file.endswith('.py') or file.endswith('.html')): 
    101                     thefile = file 
    102                     if file.endswith('.html'): 
    103                         src = open(os.path.join(dirpath, file), "rb").read() 
    104                         thefile = '%s.py' % file 
    105                         open(os.path.join(dirpath, thefile), "wb").write(templatize(src)) 
    106                     if verbose: 
    107                         sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) 
    108                     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"' % ( 
    109                         domain, os.path.join(dirpath, thefile)) 
    110                     (stdin, stdout, stderr) = os.popen3(cmd, 't') 
    111                     msgs = stdout.read() 
    112                     errors = stderr.read() 
    113                     if errors: 
    114                         print "errors happened while running xgettext on %s" % file 
    115                         print errors 
    116                         sys.exit(8) 
    117                     if thefile != file: 
    118                         old = '#: '+os.path.join(dirpath, thefile)[2:] 
    119                         new = '#: '+os.path.join(dirpath, file)[2:] 
    120                         msgs = msgs.replace(old, new) 
    121                     if os.path.exists(potfile): 
    122                         # Strip the header 
    123                         msgs = '\n'.join(dropwhile(len, msgs.split('\n'))) 
    124                     else: 
    125                         msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8') 
    126                     if msgs: 
    127                         open(potfile, 'ab').write(msgs) 
    128                     if thefile != file: 
    129                         os.unlink(os.path.join(dirpath, thefile)) 
    130133 
    131134        if os.path.exists(potfile):