# HG changeset patch # User Patrick Mezard # Date 2010-10-24 10:52:37 # Node ID 80deae3bc5ea74a160c79788e8064a3db0235b98 # Parent f13acb96b2a73bf3603fb5b664cd16e6364bcc1f hggettext: handle i18nfunctions declaration for docstrings translations diff --git a/hgext/bookmarks.py b/hgext/bookmarks.py --- a/hgext/bookmarks.py +++ b/hgext/bookmarks.py @@ -566,3 +566,6 @@ cmdtable = { } colortable = {'bookmarks.current': 'green'} + +# tell hggettext to extract docstrings from these functions: +i18nfunctions = [bmrevset] diff --git a/hgext/transplant.py b/hgext/transplant.py --- a/hgext/transplant.py +++ b/hgext/transplant.py @@ -625,3 +625,6 @@ cmdtable = { _('hg transplant [-s REPO] [-b BRANCH [-a]] [-p REV] ' '[-m REV] [REV]...')) } + +# tell hggettext to extract docstrings from these functions: +i18nfunctions = [revsettransplanted] diff --git a/i18n/hggettext b/i18n/hggettext --- a/i18n/hggettext +++ b/i18n/hggettext @@ -97,19 +97,25 @@ def docstrings(path): lineno = 1 + offset(src, mod.__doc__, path, 7) print poentry(path, lineno, mod.__doc__) + functions = list(getattr(mod, 'i18nfunctions', [])) + functions = [(f, True) for f in functions] + cmdtable = getattr(mod, 'cmdtable', {}) if not cmdtable: # Maybe we are processing mercurial.commands? cmdtable = getattr(mod, 'table', {}) + functions.extend((c[0], False) for c in cmdtable.itervalues()) - for entry in cmdtable.itervalues(): - func = entry[0] + for func, rstrip in functions: if func.__doc__: src = inspect.getsource(func) name = "%s.%s" % (path, func.__name__) lineno = func.func_code.co_firstlineno - lineno += offset(src, func.__doc__, name, 1) - print poentry(path, lineno, func.__doc__) + doc = func.__doc__ + if rstrip: + doc = doc.rstrip() + lineno += offset(src, doc, name, 1) + print poentry(path, lineno, doc) def rawtext(path): diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -791,3 +791,6 @@ def makedoc(topic, doc): predicates = '\n'.join(predicates) doc = doc.replace('.. predicatesmarker', predicates) return doc + +# tell hggettext to extract docstrings from these functions: +i18nfunctions = symbols.values()