summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2001-05-24 23:06:13 (GMT)
committerBarry Warsaw <barry@python.org>2001-05-24 23:06:13 (GMT)
commit50cf706b5c3238ced48cc849532bf17f6c7c9197 (patch)
tree08dcb12ce8b356c1a54b773e829e2cddbbbdcfa5 /Tools
parentcd35306a25ef4a7c67edc50f0cec0af5a4b7ea41 (diff)
downloadcpython-50cf706b5c3238ced48cc849532bf17f6c7c9197.zip
cpython-50cf706b5c3238ced48cc849532bf17f6c7c9197.tar.gz
cpython-50cf706b5c3238ced48cc849532bf17f6c7c9197.tar.bz2
write(): Aggressively sort all catalog entries, and fix the bug where
there were multiple translatable strings on a single line of source code.
Diffstat (limited to 'Tools')
-rwxr-xr-xTools/i18n/pygettext.py72
1 files changed, 37 insertions, 35 deletions
diff --git a/Tools/i18n/pygettext.py b/Tools/i18n/pygettext.py
index 14a83b4..a4bf01f 100755
--- a/Tools/i18n/pygettext.py
+++ b/Tools/i18n/pygettext.py
@@ -331,45 +331,47 @@ class TokenEater:
for k, v in self.__messages.items():
keys = v.keys()
keys.sort()
- reverse[tuple(keys)] = (k, v)
+ reverse.setdefault(tuple(keys), []).append((k, v))
rkeys = reverse.keys()
rkeys.sort()
for rkey in rkeys:
- k, v = reverse[rkey]
- # 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()):
- print >> fp, '#. docstring'
- # 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
- # name and then by line number.
- v = v.keys()
- v.sort()
- if not options.writelocations:
- pass
- # location comments are different b/w Solaris and GNU:
- elif options.locationstyle == options.SOLARIS:
- for filename, lineno in v:
- d = {'filename': filename, 'lineno': lineno}
- print >>fp, _('# File: %(filename)s, line: %(lineno)d') % d
- elif options.locationstyle == options.GNU:
- # fit as many locations on one line, as long as the
- # resulting line length doesn't exceeds 'options.width'
- locline = '#:'
- for filename, lineno in v:
- d = {'filename': filename, 'lineno': lineno}
- s = _(' %(filename)s:%(lineno)d') % d
- if len(locline) + len(s) <= options.width:
- locline = locline + s
- else:
+ rentries = reverse[rkey]
+ rentries.sort()
+ for k, v in rentries:
+ # 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()):
+ print >> fp, '#. docstring'
+ # 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 name and then by line number.
+ v = v.keys()
+ v.sort()
+ if not options.writelocations:
+ pass
+ # location comments are different b/w Solaris and GNU:
+ elif options.locationstyle == options.SOLARIS:
+ for filename, lineno in v:
+ d = {'filename': filename, 'lineno': lineno}
+ print >>fp, _(
+ '# File: %(filename)s, line: %(lineno)d') % d
+ elif options.locationstyle == options.GNU:
+ # fit as many locations on one line, as long as the
+ # resulting line length doesn't exceeds 'options.width'
+ locline = '#:'
+ for filename, lineno in v:
+ d = {'filename': filename, 'lineno': lineno}
+ 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
- locline = "#:" + s
- if len(locline) > 2:
- print >> fp, locline
- # TBD: sorting, normalizing
- print >> fp, 'msgid', normalize(k)
- print >> fp, 'msgstr ""\n'
+ print >> fp, 'msgid', normalize(k)
+ print >> fp, 'msgstr ""\n'