diff options
-rwxr-xr-x | Tools/i18n/pygettext.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/Tools/i18n/pygettext.py b/Tools/i18n/pygettext.py index 41a0970..9882952 100755 --- a/Tools/i18n/pygettext.py +++ b/Tools/i18n/pygettext.py @@ -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, {})[entry] = 1 + self.__messages.setdefault(msg, {})[entry] = isdocstring def set_filename(self, filename): self.__curfile = filename @@ -325,6 +326,11 @@ 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. |