Skip to content

Commit c351ce6

Browse files
authored
bpo-28331: fix impl-detail label is removed when content is translated. (pythonGH-195)
1 parent c45cd16 commit c351ce6

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

Doc/tools/extensions/pyspecific.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
from sphinx import addnodes
2323
from sphinx.builders import Builder
24+
from sphinx.locale import translators
2425
from sphinx.util.nodes import split_explicit_title
2526
from sphinx.util.compat import Directive
2627
from sphinx.writers.html import HTMLTranslator
@@ -103,16 +104,25 @@ class ImplementationDetail(Directive):
103104
optional_arguments = 1
104105
final_argument_whitespace = True
105106

107+
# This text is copied to templates/dummy.html
108+
label_text = 'CPython implementation detail:'
109+
106110
def run(self):
107111
pnode = nodes.compound(classes=['impl-detail'])
112+
label = translators['sphinx'].gettext(self.label_text)
108113
content = self.content
109-
add_text = nodes.strong('CPython implementation detail:',
110-
'CPython implementation detail:')
114+
add_text = nodes.strong(label, label)
111115
if self.arguments:
112116
n, m = self.state.inline_text(self.arguments[0], self.lineno)
113117
pnode.append(nodes.paragraph('', '', *(n + m)))
114118
self.state.nested_parse(content, self.content_offset, pnode)
115119
if pnode.children and isinstance(pnode[0], nodes.paragraph):
120+
content = nodes.inline(pnode[0].rawsource, translatable=True)
121+
content.source = pnode[0].source
122+
content.line = pnode[0].line
123+
content += pnode[0].children
124+
pnode[0].replace_self(nodes.paragraph('', '', content,
125+
translatable=False))
116126
pnode[0].insert(0, add_text)
117127
pnode[0].insert(1, nodes.Text(' '))
118128
else:

Doc/tools/templates/dummy.html

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
This file is not an actual template, but used to add some
2+
texts in extensions to sphinx.pot file.
3+
4+
In extensions/pyspecific.py:
5+
6+
{% trans %}CPython implementation detail:{% endtrans %}

0 commit comments

Comments
 (0)