[docs] "CPython implementation detail:" is removed when contents is translated (issue 28331)

songofacandy at gmail.com songofacandy at gmail.com
Wed Oct 5 03:51:09 EDT 2016


Reviewers: Mariatta,

Message:
Thanks.


http://bugs.python.org/review/28331/diff/18722/Doc/tools/extensions/pyspecific.py
File Doc/tools/extensions/pyspecific.py (right):

http://bugs.python.org/review/28331/diff/18722/Doc/tools/extensions/pyspecific.py#newcode24
Doc/tools/extensions/pyspecific.py:24: import sphinx.locale
On 2016/10/05 07:58:24, Mariatta wrote:
> seems like it's more of a common pattern to do:
> 
> from sphinx.locale import translators
> 
> and then line 112 can become:
> 
> label = translators['sphinx'].gettext(self.label_text)
> 
> but maybe I'm too nitpicky :)

Done.

http://bugs.python.org/review/28331/diff/18722/Doc/tools/extensions/pyspecific.py#newcode124
Doc/tools/extensions/pyspecific.py:124:
pnode[0].replace_self(nodes.paragraph('', '', content,
translatable=False))
On 2016/10/05 07:58:24, Mariatta wrote:
> The line is kinda long.
> Do you think it could be broken using continuation line?
> 
> Thanks.

Done.



Please review this at http://bugs.python.org/review/28331/

Affected files:
  Doc/tools/extensions/pyspecific.py
  Doc/tools/templates/dummy.html


diff -r 02eb35b79af0 Doc/tools/extensions/pyspecific.py
--- a/Doc/tools/extensions/pyspecific.py	Wed Sep 28 21:57:25 2016 -0400
+++ b/Doc/tools/extensions/pyspecific.py	Sat Oct 01 22:25:22 2016 +0900
@@ -21,6 +21,7 @@
 
 from sphinx import addnodes
 from sphinx.builders import Builder
+import sphinx.locale
 from sphinx.util.nodes import split_explicit_title
 from sphinx.util.compat import Directive
 from sphinx.writers.html import HTMLTranslator
@@ -103,16 +104,24 @@
     optional_arguments = 1
     final_argument_whitespace = True
 
+    # This text is copied to templates/dummy.html
+    label_text = 'CPython implementation detail:'
+
     def run(self):
         pnode = nodes.compound(classes=['impl-detail'])
+        label = sphinx.locale.translators['sphinx'].gettext(self.label_text)
         content = self.content
-        add_text = nodes.strong('CPython implementation detail:',
-                                'CPython implementation detail:')
+        add_text = nodes.strong(label, label)
         if self.arguments:
             n, m = self.state.inline_text(self.arguments[0], self.lineno)
             pnode.append(nodes.paragraph('', '', *(n + m)))
         self.state.nested_parse(content, self.content_offset, pnode)
         if pnode.children and isinstance(pnode[0], nodes.paragraph):
+            content = nodes.inline(pnode[0].rawsource, translatable=True)
+            content.source = pnode[0].source
+            content.line = pnode[0].line
+            content += pnode[0].children
+            pnode[0].replace_self(nodes.paragraph('', '', content, translatable=False))
             pnode[0].insert(0, add_text)
             pnode[0].insert(1, nodes.Text(' '))
         else:
diff -r 02eb35b79af0 Doc/tools/templates/dummy.html
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Doc/tools/templates/dummy.html	Sat Oct 01 22:25:22 2016 +0900
@@ -0,0 +1,6 @@
+This file is not an actual template, but used to add some
+texts in extensions to sphinx.pot file.
+
+In extensions/pyspecific.py:
+
+{% trans %}CPython implementation detail:{% endtrans %}




More information about the docs mailing list