Mercurial > hg
comparison i18n/hggettext @ 12823:80deae3bc5ea stable
hggettext: handle i18nfunctions declaration for docstrings translations
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Sun, 24 Oct 2010 12:52:37 +0200 |
parents | 25e572394f5c |
children | 2516bba643e7 |
comparison
equal
deleted
inserted
replaced
12822:f13acb96b2a7 | 12823:80deae3bc5ea |
---|---|
95 if mod.__doc__: | 95 if mod.__doc__: |
96 src = open(path).read() | 96 src = open(path).read() |
97 lineno = 1 + offset(src, mod.__doc__, path, 7) | 97 lineno = 1 + offset(src, mod.__doc__, path, 7) |
98 print poentry(path, lineno, mod.__doc__) | 98 print poentry(path, lineno, mod.__doc__) |
99 | 99 |
100 functions = list(getattr(mod, 'i18nfunctions', [])) | |
101 functions = [(f, True) for f in functions] | |
102 | |
100 cmdtable = getattr(mod, 'cmdtable', {}) | 103 cmdtable = getattr(mod, 'cmdtable', {}) |
101 if not cmdtable: | 104 if not cmdtable: |
102 # Maybe we are processing mercurial.commands? | 105 # Maybe we are processing mercurial.commands? |
103 cmdtable = getattr(mod, 'table', {}) | 106 cmdtable = getattr(mod, 'table', {}) |
107 functions.extend((c[0], False) for c in cmdtable.itervalues()) | |
104 | 108 |
105 for entry in cmdtable.itervalues(): | 109 for func, rstrip in functions: |
106 func = entry[0] | |
107 if func.__doc__: | 110 if func.__doc__: |
108 src = inspect.getsource(func) | 111 src = inspect.getsource(func) |
109 name = "%s.%s" % (path, func.__name__) | 112 name = "%s.%s" % (path, func.__name__) |
110 lineno = func.func_code.co_firstlineno | 113 lineno = func.func_code.co_firstlineno |
111 lineno += offset(src, func.__doc__, name, 1) | 114 doc = func.__doc__ |
112 print poentry(path, lineno, func.__doc__) | 115 if rstrip: |
116 doc = doc.rstrip() | |
117 lineno += offset(src, doc, name, 1) | |
118 print poentry(path, lineno, doc) | |
113 | 119 |
114 | 120 |
115 def rawtext(path): | 121 def rawtext(path): |
116 src = open(path).read() | 122 src = open(path).read() |
117 print poentry(path, 1, src) | 123 print poentry(path, 1, src) |