bpo-28331: fix impl-detail label is removed when content is translate… · python/cpython@c351ce6 (original) (raw)
`@@ -21,6 +21,7 @@
`
21
21
``
22
22
`from sphinx import addnodes
`
23
23
`from sphinx.builders import Builder
`
``
24
`+
from sphinx.locale import translators
`
24
25
`from sphinx.util.nodes import split_explicit_title
`
25
26
`from sphinx.util.compat import Directive
`
26
27
`from sphinx.writers.html import HTMLTranslator
`
`@@ -103,16 +104,25 @@ class ImplementationDetail(Directive):
`
103
104
`optional_arguments = 1
`
104
105
`final_argument_whitespace = True
`
105
106
``
``
107
`+
This text is copied to templates/dummy.html
`
``
108
`+
label_text = 'CPython implementation detail:'
`
``
109
+
106
110
`def run(self):
`
107
111
`pnode = nodes.compound(classes=['impl-detail'])
`
``
112
`+
label = translators['sphinx'].gettext(self.label_text)
`
108
113
`content = self.content
`
109
``
`-
add_text = nodes.strong('CPython implementation detail:',
`
110
``
`-
'CPython implementation detail:')
`
``
114
`+
add_text = nodes.strong(label, label)
`
111
115
`if self.arguments:
`
112
116
`n, m = self.state.inline_text(self.arguments[0], self.lineno)
`
113
117
`pnode.append(nodes.paragraph('', '', *(n + m)))
`
114
118
`self.state.nested_parse(content, self.content_offset, pnode)
`
115
119
`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))
`
116
126
`pnode[0].insert(0, add_text)
`
117
127
`pnode[0].insert(1, nodes.Text(' '))
`
118
128
`else:
`