mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-101845: pyspecific: Fix i18n for availability directive (GH-101846)
pyspecific: Fix i18n for availability directive If the directive has content, the previous code would nest paragraph nodes from that content inside a general paragraph node, which confuses Sphinx and leads it to drop the content when translating. Instead, use a container node for the body. Also use set_source_info so that any warnings have location info.
This commit is contained in:
parent
dfc2e065a2
commit
6ef6915d35
1 changed files with 11 additions and 9 deletions
|
@ -28,6 +28,7 @@ except ImportError:
|
|||
from sphinx.environment import NoUri
|
||||
from sphinx.locale import _ as sphinx_gettext
|
||||
from sphinx.util import status_iterator, logging
|
||||
from sphinx.util.docutils import SphinxDirective
|
||||
from sphinx.util.nodes import split_explicit_title
|
||||
from sphinx.writers.text import TextWriter, TextTranslator
|
||||
|
||||
|
@ -119,7 +120,7 @@ class ImplementationDetail(Directive):
|
|||
|
||||
# Support for documenting platform availability
|
||||
|
||||
class Availability(Directive):
|
||||
class Availability(SphinxDirective):
|
||||
|
||||
has_content = True
|
||||
required_arguments = 1
|
||||
|
@ -139,18 +140,19 @@ class Availability(Directive):
|
|||
|
||||
def run(self):
|
||||
availability_ref = ':ref:`Availability <availability>`: '
|
||||
avail_nodes, avail_msgs = self.state.inline_text(
|
||||
availability_ref + self.arguments[0],
|
||||
self.lineno)
|
||||
pnode = nodes.paragraph(availability_ref + self.arguments[0],
|
||||
classes=["availability"],)
|
||||
n, m = self.state.inline_text(availability_ref, self.lineno)
|
||||
pnode.extend(n + m)
|
||||
n, m = self.state.inline_text(self.arguments[0], self.lineno)
|
||||
pnode.extend(n + m)
|
||||
'', *avail_nodes, *avail_msgs)
|
||||
self.set_source_info(pnode)
|
||||
cnode = nodes.container("", pnode, classes=["availability"])
|
||||
self.set_source_info(cnode)
|
||||
if self.content:
|
||||
self.state.nested_parse(self.content, self.content_offset, pnode)
|
||||
|
||||
self.state.nested_parse(self.content, self.content_offset, cnode)
|
||||
self.parse_platforms()
|
||||
|
||||
return [pnode]
|
||||
return [cnode]
|
||||
|
||||
def parse_platforms(self):
|
||||
"""Parse platform information from arguments
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue