Mercurial > hg
comparison i18n/hggettext @ 33818:ed04d7254a91
i18n: use saved object to get actual function information if available
To list up available compression types instead of
".. bundlecompressionmarker" in "hg help bundlespec" output, proxy
object "docobject" is used, because:
- current online help system requires that __doc__ of registered
object (maybe, function) is already well formatted in reST syntax
- bundletype() method of compressionengine classes is used to list up
available compression types, but
- __doc__ of bundletype() object (= "instancemethod") is read-only
On the other hand, hggettext requires original function object, in
order to get document location in source code.
Therefore, description of each compression types isn't yet
translatable. Even if translatable, translators should make much
effort to determine location of original texts in source code.
To get actual function information, this patch makes hggettext use
function object saved as "_origfunc", if it is available. This patch
also changes bundlecompressiontopics() side, in order to explain how
these changes work easily.
This patch is a part of preparations for making description of each
compression types translatable.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Tue, 15 Aug 2017 19:27:24 +0900 |
parents | 726dd73df3b9 |
children | d5ef17608159 |
comparison
equal
deleted
inserted
replaced
33817:726dd73df3b9 | 33818:ed04d7254a91 |
---|---|
117 cmdtable = getattr(mod, 'table', {}) | 117 cmdtable = getattr(mod, 'table', {}) |
118 functions.extend((c[0], False) for c in cmdtable.itervalues()) | 118 functions.extend((c[0], False) for c in cmdtable.itervalues()) |
119 | 119 |
120 for func, rstrip in functions: | 120 for func, rstrip in functions: |
121 if func.__doc__: | 121 if func.__doc__: |
122 docobj = func # this might be a proxy to provide formatted doc | |
123 func = getattr(func, '_origfunc', func) | |
122 funcmod = inspect.getmodule(func) | 124 funcmod = inspect.getmodule(func) |
123 extra = '' | 125 extra = '' |
124 if funcmod.__package__ == funcmod.__name__: | 126 if funcmod.__package__ == funcmod.__name__: |
125 extra = '/__init__' | 127 extra = '/__init__' |
126 actualpath = '%s%s.py' % (funcmod.__name__.replace('.', '/'), extra) | 128 actualpath = '%s%s.py' % (funcmod.__name__.replace('.', '/'), extra) |
127 | 129 |
128 src = inspect.getsource(func) | 130 src = inspect.getsource(func) |
129 name = "%s.%s" % (actualpath, func.__name__) | 131 name = "%s.%s" % (actualpath, func.__name__) |
130 lineno = inspect.getsourcelines(func)[1] | 132 lineno = inspect.getsourcelines(func)[1] |
131 doc = func.__doc__ | 133 doc = docobj.__doc__ |
132 origdoc = getattr(func, '_origdoc', '') | 134 origdoc = getattr(docobj, '_origdoc', '') |
133 if rstrip: | 135 if rstrip: |
134 doc = doc.rstrip() | 136 doc = doc.rstrip() |
135 origdoc = origdoc.rstrip() | 137 origdoc = origdoc.rstrip() |
136 if origdoc: | 138 if origdoc: |
137 lineno += offset(src, origdoc, name, 1) | 139 lineno += offset(src, origdoc, name, 1) |