diff options
| author | bwarsaw | 2001-05-22 05:26:43 +0000 |
|---|---|---|
| committer | bwarsaw | 2001-05-22 05:26:43 +0000 |
| commit | 0e72b23371337284b8fc66d88f4166cfeabc4d9e (patch) | |
| tree | f776a8c697595036dd0086587dc1cd820059ddab /bin/pygettext.py | |
| parent | 4874a11e53f47230dc87b70cd2352cb90cbb893a (diff) | |
| download | mailman-0e72b23371337284b8fc66d88f4166cfeabc4d9e.tar.gz mailman-0e72b23371337284b8fc66d88f4166cfeabc4d9e.tar.zst mailman-0e72b23371337284b8fc66d88f4166cfeabc4d9e.zip | |
Diffstat (limited to 'bin/pygettext.py')
| -rwxr-xr-x | bin/pygettext.py | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/bin/pygettext.py b/bin/pygettext.py index 275130f23..804c98c5e 100755 --- a/bin/pygettext.py +++ b/bin/pygettext.py @@ -1,7 +1,7 @@ #! /usr/bin/env python -# Originally written by Barry Warsaw <bwarsaw@python.org> +# Originally written by Barry Warsaw <barry@digicool.com> # -# minimally patched to make it even more xgettext compatible +# Minimally patched to make it even more xgettext compatible # by Peter Funk <pf@artcom-gmbh.de> """pygettext -- Python equivalent of xgettext(1) @@ -137,6 +137,7 @@ import sys import time import getopt import tokenize +import operator # for selftesting try: @@ -260,7 +261,7 @@ class TokenEater: # module docstring? if self.__freshmodule: if ttype == tokenize.STRING: - self.__addentry(safe_eval(tstring), lineno) + self.__addentry(safe_eval(tstring), lineno, isdocstring=1) self.__freshmodule = 0 elif ttype not in (tokenize.COMMENT, tokenize.NL): self.__freshmodule = 0 @@ -280,7 +281,7 @@ class TokenEater: def __suitedocstring(self, ttype, tstring, lineno): # ignore any intervening noise if ttype == tokenize.STRING: - self.__addentry(safe_eval(tstring), lineno) + self.__addentry(safe_eval(tstring), lineno, isdocstring=1) self.__state = self.__waiting elif ttype not in (tokenize.NEWLINE, tokenize.INDENT, tokenize.COMMENT): @@ -308,12 +309,12 @@ class TokenEater: self.__data.append(safe_eval(tstring)) # TBD: should we warn if we seen anything else? - def __addentry(self, msg, lineno=None): + def __addentry(self, msg, lineno=None, isdocstring=0): if lineno is None: lineno = self.__lineno if not msg in self.__options.toexclude: entry = (self.__curfile, lineno) - self.__messages.setdefault(msg, []).append(entry) + self.__messages.setdefault(msg, {})[entry] = isdocstring def set_filename(self, filename): self.__curfile = filename @@ -325,6 +326,16 @@ class TokenEater: # generated by xgettext... print >> fp, pot_header % {'time': timestamp, 'version': __version__} for k, v in self.__messages.items(): + # 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: @@ -358,7 +369,7 @@ def main(): opts, args = getopt.getopt( sys.argv[1:], 'ad:DEhk:Kno:p:S:Vvw:x:', - ['extract-all', 'default-domain', 'escape', 'help', + ['extract-all', 'default-domain=', 'escape', 'help', 'keyword=', 'no-default-keywords', 'add-location', 'no-location', 'output=', 'output-dir=', 'style=', 'verbose', 'version', 'width=', 'exclude-file=', @@ -444,8 +455,8 @@ def main(): options.toexclude = fp.readlines() fp.close() except IOError: - sys.stderr.write(_("Can't read --exclude-file: %s") % - options.excludefilename) + print >> sys.stderr, _( + "Can't read --exclude-file: %s") % options.excludefilename sys.exit(1) else: options.toexclude = [] @@ -468,8 +479,8 @@ def main(): try: tokenize.tokenize(fp.readline, eater) except tokenize.TokenError, e: - sys.stderr.write('%s: %s, line %d, column %d\n' % - (e[0], filename, e[1][0], e[1][1])) + print >> sys.stderr, '%s: %s, line %d, column %d' % ( + e[0], filename, e[1][0], e[1][1]) finally: if closep: fp.close() |
