Author: mtredinnick
Date: 2007-10-02 20:41:04 -0500 (Tue, 02 Oct 2007)
New Revision: 6445
Modified:
django/trunk/django/bin/make-messages.py
Log:
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.
Modified: django/trunk/django/bin/make-messages.py
===================================================================
--- django/trunk/django/bin/make-messages.py 2007-10-03 00:45:08 UTC (rev
6444)
+++ django/trunk/django/bin/make-messages.py 2007-10-03 01:41:04 UTC (rev
6445)
@@ -74,59 +74,62 @@
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')
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---