summaryrefslogtreecommitdiff
path: root/django/bin
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-10-03 01:41:04 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-10-03 01:41:04 +0000
commit10466470c0b950b6571abf96b52c0a8254a05ed7 (patch)
tree60f0f0e02723196068ec4119145aa953e21b5b95 /django/bin
parente79e2df47b6f98fc0670a6972440212fdb226ce6 (diff)
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
Diffstat (limited to 'django/bin')
-rwxr-xr-xdjango/bin/make-messages.py95
1 files changed, 49 insertions, 46 deletions
diff --git a/django/bin/make-messages.py b/django/bin/make-messages.py
index 11616c9ca5..44040390ea 100755
--- a/django/bin/make-messages.py
+++ b/django/bin/make-messages.py
@@ -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')