Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-84435: Make pyspecific directives translatable #19470

Merged
merged 4 commits into from
Aug 6, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions Doc/tools/extensions/pyspecific.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from sphinx.errors import NoUri
except ImportError:
from sphinx.environment import NoUri
from sphinx.locale import translators
from sphinx.locale import get_translation
from sphinx.util import status_iterator, logging
from sphinx.util.nodes import split_explicit_title
from sphinx.writers.text import TextWriter, TextTranslator
Expand All @@ -42,6 +42,8 @@

import suspicious

_ = get_translation('sphinx')


ISSUE_URI = 'https://bugs.python.org/issue?@action=redirect&bpo=%s'
GH_ISSUE_URI = 'https://github.com/python/cpython/issues/%s'
Expand Down Expand Up @@ -106,13 +108,12 @@ class ImplementationDetail(Directive):
final_argument_whitespace = True

# This text is copied to templates/dummy.html
AA-Turner marked this conversation as resolved.
Show resolved Hide resolved
label_text = 'CPython implementation detail:'
label_text = _('CPython implementation detail:')

def run(self):
pnode = nodes.compound(classes=['impl-detail'])
label = translators['sphinx'].gettext(self.label_text)
content = self.content
add_text = nodes.strong(label, label)
add_text = nodes.strong(self.label_text, self.label_text)
if self.arguments:
n, m = self.state.inline_text(self.arguments[0], self.lineno)
pnode.append(nodes.paragraph('', '', *(n + m)))
Expand Down Expand Up @@ -194,9 +195,9 @@ class AuditEvent(Directive):
final_argument_whitespace = True

_label = [
"Raises an :ref:`auditing event <auditing>` {name} with no arguments.",
"Raises an :ref:`auditing event <auditing>` {name} with argument {args}.",
"Raises an :ref:`auditing event <auditing>` {name} with arguments {args}.",
_("Raises an :ref:`auditing event <auditing>` {name} with no arguments."),
_("Raises an :ref:`auditing event <auditing>` {name} with argument {args}."),
_("Raises an :ref:`auditing event <auditing>` {name} with arguments {args}."),
]

@property
Expand All @@ -212,7 +213,7 @@ def run(self):
else:
args = []

label = translators['sphinx'].gettext(self._label[min(2, len(args))])
label = self._label[min(2, len(args))]
text = label.format(name="``{}``".format(name),
args=", ".join("``{}``".format(a) for a in args if a))

Expand Down Expand Up @@ -374,8 +375,8 @@ class DeprecatedRemoved(Directive):
final_argument_whitespace = True
option_spec = {}

_deprecated_label = 'Deprecated since version {deprecated}, will be removed in version {removed}'
_removed_label = 'Deprecated since version {deprecated}, removed in version {removed}'
_deprecated_label = _('Deprecated since version {deprecated}, will be removed in version {removed}')
_removed_label = _('Deprecated since version {deprecated}, removed in version {removed}')

def run(self):
node = addnodes.versionmodified()
Expand All @@ -390,8 +391,6 @@ def run(self):
label = self._deprecated_label
else:
label = self._removed_label

label = translators['sphinx'].gettext(label)
text = label.format(deprecated=self.arguments[0], removed=self.arguments[1])
if len(self.arguments) == 3:
inodes, messages = self.state.inline_text(self.arguments[2],
Expand Down