i18n/hggettext
changeset 29171 de28dedd1ff1
parent 29170 2516bba643e7
child 29720 041fecbb588a
equal deleted inserted replaced
29170:2516bba643e7 29171:de28dedd1ff1
    18 
    18 
    19 Use xgettext like normal to extract strings marked as translatable and
    19 Use xgettext like normal to extract strings marked as translatable and
    20 join the message cataloges to get the final catalog.
    20 join the message cataloges to get the final catalog.
    21 """
    21 """
    22 
    22 
    23 from __future__ import absolute_import
    23 from __future__ import absolute_import, print_function
    24 
    24 
    25 import inspect
    25 import inspect
    26 import os
    26 import os
    27 import sys
    27 import sys
    28 
    28 
    97     """
    97     """
    98     mod = importpath(path)
    98     mod = importpath(path)
    99     if mod.__doc__:
    99     if mod.__doc__:
   100         src = open(path).read()
   100         src = open(path).read()
   101         lineno = 1 + offset(src, mod.__doc__, path, 7)
   101         lineno = 1 + offset(src, mod.__doc__, path, 7)
   102         print poentry(path, lineno, mod.__doc__)
   102         print(poentry(path, lineno, mod.__doc__))
   103 
   103 
   104     functions = list(getattr(mod, 'i18nfunctions', []))
   104     functions = list(getattr(mod, 'i18nfunctions', []))
   105     functions = [(f, True) for f in functions]
   105     functions = [(f, True) for f in functions]
   106 
   106 
   107     cmdtable = getattr(mod, 'cmdtable', {})
   107     cmdtable = getattr(mod, 'cmdtable', {})
   117             lineno = func.func_code.co_firstlineno
   117             lineno = func.func_code.co_firstlineno
   118             doc = func.__doc__
   118             doc = func.__doc__
   119             if rstrip:
   119             if rstrip:
   120                 doc = doc.rstrip()
   120                 doc = doc.rstrip()
   121             lineno += offset(src, doc, name, 1)
   121             lineno += offset(src, doc, name, 1)
   122             print poentry(path, lineno, doc)
   122             print(poentry(path, lineno, doc))
   123 
   123 
   124 
   124 
   125 def rawtext(path):
   125 def rawtext(path):
   126     src = open(path).read()
   126     src = open(path).read()
   127     print poentry(path, 1, src)
   127     print(poentry(path, 1, src))
   128 
   128 
   129 
   129 
   130 if __name__ == "__main__":
   130 if __name__ == "__main__":
   131     # It is very important that we import the Mercurial modules from
   131     # It is very important that we import the Mercurial modules from
   132     # the source tree where hggettext is executed. Otherwise we might
   132     # the source tree where hggettext is executed. Otherwise we might