comparison i18n/hggettext @ 33621:16a175b3681e stable

i18n: use actual filename, in which function is defined, for hg.pot Before this patch, source filename for msgid in hg.pot file becomes incorrect, if a function is defined in file A, but detected in dict in file B, For example, almost all debug* commands are defined in debugcommands.py, but hggettext detects them in "table" of commands.py. Therefore, docstring fragments of debug* commands are marked as "defined in commands.py" in hg.pot file. This is serious problem for translation, because the cost to find out original location of texts increases very much.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Wed, 02 Aug 2017 00:02:11 +0900
parents 041fecbb588a
children 97ee669f1f6d
comparison
equal deleted inserted replaced
33620:cc047a733f69 33621:16a175b3681e
110 cmdtable = getattr(mod, 'table', {}) 110 cmdtable = getattr(mod, 'table', {})
111 functions.extend((c[0], False) for c in cmdtable.itervalues()) 111 functions.extend((c[0], False) for c in cmdtable.itervalues())
112 112
113 for func, rstrip in functions: 113 for func, rstrip in functions:
114 if func.__doc__: 114 if func.__doc__:
115 funcmod = inspect.getmodule(func)
116 extra = ''
117 if funcmod.__package__ == funcmod.__name__:
118 extra = '/__init__'
119 actualpath = '%s%s.py' % (funcmod.__name__.replace('.', '/'), extra)
120
115 src = inspect.getsource(func) 121 src = inspect.getsource(func)
116 name = "%s.%s" % (path, func.__name__) 122 name = "%s.%s" % (actualpath, func.__name__)
117 lineno = inspect.getsourcelines(func)[1] 123 lineno = inspect.getsourcelines(func)[1]
118 doc = func.__doc__ 124 doc = func.__doc__
119 if rstrip: 125 if rstrip:
120 doc = doc.rstrip() 126 doc = doc.rstrip()
121 lineno += offset(src, doc, name, 1) 127 lineno += offset(src, doc, name, 1)
122 print(poentry(path, lineno, doc)) 128 print(poentry(actualpath, lineno, doc))
123 129
124 130
125 def rawtext(path): 131 def rawtext(path):
126 src = open(path).read() 132 src = open(path).read()
127 print(poentry(path, 1, src)) 133 print(poentry(path, 1, src))