mirror of https://github.com/django/django.git
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. git-svn-id: http://code.djangoproject.com/svn/django/trunk@6445 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
e79e2df47b
commit
10466470c0
|
@ -74,59 +74,62 @@ def make_messages():
|
|||
if os.path.exists(potfile):
|
||||
os.unlink(potfile)
|
||||
|
||||
all_files = []
|
||||
for (dirpath, dirnames, filenames) in os.walk("."):
|
||||
for file in filenames:
|
||||
if domain == 'djangojs' and file.endswith('.js'):
|
||||
if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
|
||||
all_files.extend([(dirpath, f) for f in filenames])
|
||||
all_files.sort()
|
||||
for dirpath, file in all_files:
|
||||
if domain == 'djangojs' and file.endswith('.js'):
|
||||
if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
|
||||
src = open(os.path.join(dirpath, file), "rb").read()
|
||||
src = pythonize_re.sub('\n#', src)
|
||||
open(os.path.join(dirpath, '%s.py' % file), "wb").write(src)
|
||||
thefile = '%s.py' % file
|
||||
cmd = 'xgettext %s -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (
|
||||
os.path.exists(potfile) and '--omit-header' or '', domain, os.path.join(dirpath, thefile))
|
||||
(stdin, stdout, stderr) = os.popen3(cmd, 't')
|
||||
msgs = stdout.read()
|
||||
errors = stderr.read()
|
||||
if errors:
|
||||
print "errors happened while running xgettext on %s" % file
|
||||
print errors
|
||||
sys.exit(8)
|
||||
old = '#: '+os.path.join(dirpath, thefile)[2:]
|
||||
new = '#: '+os.path.join(dirpath, file)[2:]
|
||||
msgs = msgs.replace(old, new)
|
||||
if msgs:
|
||||
open(potfile, 'ab').write(msgs)
|
||||
os.unlink(os.path.join(dirpath, thefile))
|
||||
elif domain == 'django' and (file.endswith('.py') or file.endswith('.html')):
|
||||
thefile = file
|
||||
if file.endswith('.html'):
|
||||
src = open(os.path.join(dirpath, file), "rb").read()
|
||||
src = pythonize_re.sub('\n#', src)
|
||||
open(os.path.join(dirpath, '%s.py' % file), "wb").write(src)
|
||||
thefile = '%s.py' % file
|
||||
cmd = 'xgettext %s -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (
|
||||
os.path.exists(potfile) and '--omit-header' or '', domain, os.path.join(dirpath, thefile))
|
||||
(stdin, stdout, stderr) = os.popen3(cmd, 't')
|
||||
msgs = stdout.read()
|
||||
errors = stderr.read()
|
||||
if errors:
|
||||
print "errors happened while running xgettext on %s" % file
|
||||
print errors
|
||||
sys.exit(8)
|
||||
open(os.path.join(dirpath, thefile), "wb").write(templatize(src))
|
||||
if verbose:
|
||||
sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
|
||||
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"' % (
|
||||
domain, os.path.join(dirpath, thefile))
|
||||
(stdin, stdout, stderr) = os.popen3(cmd, 't')
|
||||
msgs = stdout.read()
|
||||
errors = stderr.read()
|
||||
if errors:
|
||||
print "errors happened while running xgettext on %s" % file
|
||||
print errors
|
||||
sys.exit(8)
|
||||
if thefile != file:
|
||||
old = '#: '+os.path.join(dirpath, thefile)[2:]
|
||||
new = '#: '+os.path.join(dirpath, file)[2:]
|
||||
msgs = msgs.replace(old, new)
|
||||
if msgs:
|
||||
open(potfile, 'ab').write(msgs)
|
||||
if os.path.exists(potfile):
|
||||
# Strip the header
|
||||
msgs = '\n'.join(dropwhile(len, msgs.split('\n')))
|
||||
else:
|
||||
msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
|
||||
if msgs:
|
||||
open(potfile, 'ab').write(msgs)
|
||||
if thefile != file:
|
||||
os.unlink(os.path.join(dirpath, thefile))
|
||||
elif domain == 'django' and (file.endswith('.py') or file.endswith('.html')):
|
||||
thefile = file
|
||||
if file.endswith('.html'):
|
||||
src = open(os.path.join(dirpath, file), "rb").read()
|
||||
thefile = '%s.py' % file
|
||||
open(os.path.join(dirpath, thefile), "wb").write(templatize(src))
|
||||
if verbose:
|
||||
sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
|
||||
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"' % (
|
||||
domain, os.path.join(dirpath, thefile))
|
||||
(stdin, stdout, stderr) = os.popen3(cmd, 't')
|
||||
msgs = stdout.read()
|
||||
errors = stderr.read()
|
||||
if errors:
|
||||
print "errors happened while running xgettext on %s" % file
|
||||
print errors
|
||||
sys.exit(8)
|
||||
if thefile != file:
|
||||
old = '#: '+os.path.join(dirpath, thefile)[2:]
|
||||
new = '#: '+os.path.join(dirpath, file)[2:]
|
||||
msgs = msgs.replace(old, new)
|
||||
if os.path.exists(potfile):
|
||||
# Strip the header
|
||||
msgs = '\n'.join(dropwhile(len, msgs.split('\n')))
|
||||
else:
|
||||
msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
|
||||
if msgs:
|
||||
open(potfile, 'ab').write(msgs)
|
||||
if thefile != file:
|
||||
os.unlink(os.path.join(dirpath, thefile))
|
||||
|
||||
if os.path.exists(potfile):
|
||||
(stdin, stdout, stderr) = os.popen3('msguniq --to-code=utf-8 "%s"' % potfile, 'b')
|
||||
|
|
Loading…
Reference in New Issue