Commit 50cf706b authored by Barry Warsaw's avatar Barry Warsaw

write(): Aggressively sort all catalog entries, and fix the bug where

there were multiple translatable strings on a single line of source
code.
parent cd35306a
...@@ -331,19 +331,21 @@ class TokenEater: ...@@ -331,19 +331,21 @@ class TokenEater:
for k, v in self.__messages.items(): for k, v in self.__messages.items():
keys = v.keys() keys = v.keys()
keys.sort() keys.sort()
reverse[tuple(keys)] = (k, v) reverse.setdefault(tuple(keys), []).append((k, v))
rkeys = reverse.keys() rkeys = reverse.keys()
rkeys.sort() rkeys.sort()
for rkey in rkeys: for rkey in rkeys:
k, v = reverse[rkey] rentries = reverse[rkey]
# If the entry was gleaned out of a docstring, then add a comment rentries.sort()
# stating so. This is to aid translators who may wish to skip for k, v in rentries:
# translating some unimportant docstrings. # If the entry was gleaned out of a docstring, then add a
# comment stating so. This is to aid translators who may wish
# to skip translating some unimportant docstrings.
if reduce(operator.__add__, v.values()): if reduce(operator.__add__, v.values()):
print >> fp, '#. docstring' print >> fp, '#. docstring'
# k is the message string, v is a dictionary-set of (filename, # k is the message string, v is a dictionary-set of (filename,
# lineno) tuples. We want to sort the entries in v first by file # lineno) tuples. We want to sort the entries in v first by
# name and then by line number. # file name and then by line number.
v = v.keys() v = v.keys()
v.sort() v.sort()
if not options.writelocations: if not options.writelocations:
...@@ -352,7 +354,8 @@ class TokenEater: ...@@ -352,7 +354,8 @@ class TokenEater:
elif options.locationstyle == options.SOLARIS: elif options.locationstyle == options.SOLARIS:
for filename, lineno in v: for filename, lineno in v:
d = {'filename': filename, 'lineno': lineno} d = {'filename': filename, 'lineno': lineno}
print >>fp, _('# File: %(filename)s, line: %(lineno)d') % d print >>fp, _(
'# File: %(filename)s, line: %(lineno)d') % d
elif options.locationstyle == options.GNU: elif options.locationstyle == options.GNU:
# fit as many locations on one line, as long as the # fit as many locations on one line, as long as the
# resulting line length doesn't exceeds 'options.width' # resulting line length doesn't exceeds 'options.width'
...@@ -367,7 +370,6 @@ class TokenEater: ...@@ -367,7 +370,6 @@ class TokenEater:
locline = "#:" + s locline = "#:" + s
if len(locline) > 2: if len(locline) > 2:
print >> fp, locline print >> fp, locline
# TBD: sorting, normalizing
print >> fp, 'msgid', normalize(k) print >> fp, 'msgid', normalize(k)
print >> fp, 'msgstr ""\n' print >> fp, 'msgstr ""\n'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment