Skip to content

Commit 7ebf41b

Browse files
authored
Use :term: instead for translators (#81)
2 parents 2d493f0 + a16ca8b commit 7ebf41b

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

Doc/tools/extensions/changes.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from __future__ import annotations
44

5+
import re
6+
57
from docutils import nodes
68
from sphinx import addnodes
79
from sphinx.domains.changeset import (
@@ -87,9 +89,11 @@ class SoftDeprecated(PyVersionChange):
8789
with "Soft deprecated" linking to the glossary definition.
8890
"""
8991

92+
_TERM_RE = re.compile(r":term:`([^`]+)`")
93+
9094
def run(self) -> list[Node]:
9195
versionlabels[self.name] = sphinx_gettext(
92-
"Soft deprecated since version %s"
96+
":term:`Soft deprecated` since version %s"
9397
)
9498
versionlabel_classes[self.name] = "soft-deprecated"
9599
try:
@@ -108,38 +112,35 @@ def run(self) -> list[Node]:
108112

109113
return result
110114

111-
@staticmethod
112-
def _add_glossary_link(inline: nodes.inline) -> None:
113-
"""Replace 'Soft deprecated' text with a cross-reference to the
114-
:term:`soft deprecated` glossary entry."""
115-
marker = sphinx_gettext("Soft deprecated")
116-
ref = addnodes.pending_xref(
117-
"",
118-
nodes.Text(marker),
119-
refdomain="std",
120-
reftype="term",
121-
reftarget="soft deprecated",
122-
refwarn=True,
123-
)
124-
115+
@classmethod
116+
def _add_glossary_link(cls, inline: nodes.inline) -> None:
117+
"""Replace :term:`soft deprecated` text with a cross-reference to the
118+
'Soft deprecated' glossary entry."""
125119
for child in inline.children:
126120
if not isinstance(child, nodes.Text):
127121
continue
128122

129123
text = str(child)
130-
idx = text.find(marker)
131-
if idx < 0:
124+
match = cls._TERM_RE.search(text)
125+
if match is None:
132126
continue
133127

134-
# Replace the text node with the split parts using docutils API
135-
new_nodes: list[nodes.Node] = []
136-
if idx > 0:
137-
new_nodes.append(nodes.Text(text[:idx]))
128+
ref = addnodes.pending_xref(
129+
"",
130+
nodes.Text(match.group(1)),
131+
refdomain="std",
132+
reftype="term",
133+
reftarget="soft deprecated",
134+
refwarn=True,
135+
)
138136

137+
start, end = match.span()
138+
new_nodes: list[nodes.Node] = []
139+
if start > 0:
140+
new_nodes.append(nodes.Text(text[:start]))
139141
new_nodes.append(ref)
140-
remainder = text[idx + len(marker) :]
141-
if remainder:
142-
new_nodes.append(nodes.Text(remainder))
142+
if end < len(text):
143+
new_nodes.append(nodes.Text(text[end:]))
143144

144145
child.parent.replace(child, new_nodes)
145146
break

Doc/tools/templates/dummy.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929

3030
{% trans %}Deprecated since version %s, will be removed in version %s{% endtrans %}
3131
{% trans %}Deprecated since version %s, removed in version %s{% endtrans %}
32-
{% trans %}Soft deprecated since version %s{% endtrans %}
33-
{% trans %}Soft deprecated{% endtrans %}
32+
{% trans %}:term:`Soft deprecated` since version %s{% endtrans %}
3433

3534
In docsbuild-scripts, when rewriting indexsidebar.html with actual versions:
3635

0 commit comments

Comments
 (0)