pytho****@googl*****
pytho****@googl*****
2012年 11月 24日 (土) 04:03:45 JST
Revision: 95017eba852f Branch: default Author: Nozomu Kaneko <nozom****@gmail*****> Date: Fri Nov 23 10:41:20 2012 Log: Add custom Transform to make versionmodified nodes translatable. http://code.google.com/p/python-doc-ja/source/detail?r=95017eba852f&repo=py33 Modified: /tools/sphinxext/jpsupport.py ======================================= --- /tools/sphinxext/jpsupport.py Fri Nov 16 13:01:43 2012 +++ /tools/sphinxext/jpsupport.py Fri Nov 23 10:41:20 2012 @@ -77,6 +77,39 @@ node += nodes.Text("#") +from docutils.transforms import Transform +class I18nDoctreeFixer(Transform): + # make sure be higher than Locale transformer + default_priority = -1 + + def apply(self): + from docutils import nodes + from sphinx import addnodes + + # Note: node that has following criteria is basically translatable: + # + # 1. instance of docutils.nodes.TextElement + # 2. not a kind of the "ignored" nodes + # 3. has source attribute + # 4. has non-empty rawsource attribute + # + # See :func:`extract_messages` in :mod:`shpinx.util.nodes` for detail. + + # versionmodified + for node in self.document.traverse(addnodes.versionmodified): + rawsource = "".join([c.rawsource for c in node.children]) + if not rawsource: + continue + para = nodes.paragraph() + for child in node.children: + para += child + para.source = node.source + para.line = node.line + para.rawsource = rawsource + node.clear() + node += para + + def setup(app): app.add_config_value('japanesesupport_trunc_whitespace', True, True) app.add_config_value('japanesesupport_separate_markup', True, True) @@ -86,3 +119,6 @@ app.connect("source-read", separate_markup) # app.connect("source-read", hash_after) app.connect("doctree-resolved", fix_reference) + + from sphinx.environment import SphinxStandaloneReader + SphinxStandaloneReader.transforms.append(I18nDoctreeFixer)