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,45 +331,47 @@ class TokenEater: ...@@ -331,45 +331,47 @@ 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
if reduce(operator.__add__, v.values()): # comment stating so. This is to aid translators who may wish
print >> fp, '#. docstring' # to skip translating some unimportant docstrings.
# k is the message string, v is a dictionary-set of (filename, if reduce(operator.__add__, v.values()):
# lineno) tuples. We want to sort the entries in v first by file print >> fp, '#. docstring'
# name and then by line number. # k is the message string, v is a dictionary-set of (filename,
v = v.keys() # lineno) tuples. We want to sort the entries in v first by
v.sort() # file name and then by line number.
if not options.writelocations: v = v.keys()
pass v.sort()
# location comments are different b/w Solaris and GNU: if not options.writelocations:
elif options.locationstyle == options.SOLARIS: pass
for filename, lineno in v: # location comments are different b/w Solaris and GNU:
d = {'filename': filename, 'lineno': lineno} elif options.locationstyle == options.SOLARIS:
print >>fp, _('# File: %(filename)s, line: %(lineno)d') % d for filename, lineno in v:
elif options.locationstyle == options.GNU: d = {'filename': filename, 'lineno': lineno}
# fit as many locations on one line, as long as the print >>fp, _(
# resulting line length doesn't exceeds 'options.width' '# File: %(filename)s, line: %(lineno)d') % d
locline = '#:' elif options.locationstyle == options.GNU:
for filename, lineno in v: # fit as many locations on one line, as long as the
d = {'filename': filename, 'lineno': lineno} # resulting line length doesn't exceeds 'options.width'
s = _(' %(filename)s:%(lineno)d') % d locline = '#:'
if len(locline) + len(s) <= options.width: for filename, lineno in v:
locline = locline + s d = {'filename': filename, 'lineno': lineno}
else: s = _(' %(filename)s:%(lineno)d') % d
if len(locline) + len(s) <= options.width:
locline = locline + s
else:
print >> fp, locline
locline = "#:" + s
if len(locline) > 2:
print >> fp, locline print >> fp, locline
locline = "#:" + s print >> fp, 'msgid', normalize(k)
if len(locline) > 2: print >> fp, 'msgstr ""\n'
print >> fp, locline
# TBD: sorting, normalizing
print >> fp, 'msgid', normalize(k)
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