hggettext: handle i18nfunctions declaration for docstrings translations stable
authorPatrick Mezard <pmezard@gmail.com>
Sun, 24 Oct 2010 12:52:37 +0200
branchstable
changeset 12823 80deae3bc5ea
parent 12822 f13acb96b2a7
child 12824 93d6559a9cbc
hggettext: handle i18nfunctions declaration for docstrings translations
hgext/bookmarks.py
hgext/transplant.py
i18n/hggettext
mercurial/revset.py
--- a/hgext/bookmarks.py	Sat Oct 23 19:22:42 2010 +0200
+++ b/hgext/bookmarks.py	Sun Oct 24 12:52:37 2010 +0200
@@ -566,3 +566,6 @@
 }
 
 colortable = {'bookmarks.current': 'green'}
+
+# tell hggettext to extract docstrings from these functions:
+i18nfunctions = [bmrevset]
--- a/hgext/transplant.py	Sat Oct 23 19:22:42 2010 +0200
+++ b/hgext/transplant.py	Sun Oct 24 12:52:37 2010 +0200
@@ -625,3 +625,6 @@
          _('hg transplant [-s REPO] [-b BRANCH [-a]] [-p REV] '
            '[-m REV] [REV]...'))
 }
+
+# tell hggettext to extract docstrings from these functions:
+i18nfunctions = [revsettransplanted]
--- a/i18n/hggettext	Sat Oct 23 19:22:42 2010 +0200
+++ b/i18n/hggettext	Sun Oct 24 12:52:37 2010 +0200
@@ -97,19 +97,25 @@
         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):
--- a/mercurial/revset.py	Sat Oct 23 19:22:42 2010 +0200
+++ b/mercurial/revset.py	Sun Oct 24 12:52:37 2010 +0200
@@ -791,3 +791,6 @@
     predicates = '\n'.join(predicates)
     doc = doc.replace('.. predicatesmarker', predicates)
     return doc
+
+# tell hggettext to extract docstrings from these functions:
+i18nfunctions = symbols.values()