From b13ef53d46514b61b33d3db5f59c409b393b7cd4 Mon Sep 17 00:00:00 2001 From: cocoatomo Date: Sat, 11 Apr 2020 16:28:59 +0900 Subject: [PATCH 1/2] Have pyspecific directives translatable --- Doc/tools/extensions/pyspecific.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Doc/tools/extensions/pyspecific.py b/Doc/tools/extensions/pyspecific.py index ff522c98d0f629..0e54b84c3e7e9f 100644 --- a/Doc/tools/extensions/pyspecific.py +++ b/Doc/tools/extensions/pyspecific.py @@ -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 @@ -42,6 +42,8 @@ import suspicious +_ = get_translation('sphinx') + ISSUE_URI = 'https://bugs.python.org/issue%s' SOURCE_URI = 'https://github.com/python/cpython/tree/main/%s' @@ -83,13 +85,12 @@ class ImplementationDetail(Directive): final_argument_whitespace = True # This text is copied to templates/dummy.html - 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))) @@ -171,9 +172,9 @@ class AuditEvent(Directive): final_argument_whitespace = True _label = [ - "Raises an :ref:`auditing event ` {name} with no arguments.", - "Raises an :ref:`auditing event ` {name} with argument {args}.", - "Raises an :ref:`auditing event ` {name} with arguments {args}.", + _("Raises an :ref:`auditing event ` {name} with no arguments."), + _("Raises an :ref:`auditing event ` {name} with argument {args}."), + _("Raises an :ref:`auditing event ` {name} with arguments {args}."), ] @property @@ -189,7 +190,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)) @@ -351,8 +352,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() @@ -367,8 +368,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], From 7f787261bdfec7d30dcd444bbd7d2d2b540e17dc Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sun, 6 Aug 2023 05:21:28 +0100 Subject: [PATCH 2/2] De-duplicate translations --- Doc/tools/extensions/pyspecific.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/Doc/tools/extensions/pyspecific.py b/Doc/tools/extensions/pyspecific.py index 91fff953de3671..765e6383ac6f5e 100644 --- a/Doc/tools/extensions/pyspecific.py +++ b/Doc/tools/extensions/pyspecific.py @@ -23,7 +23,7 @@ from sphinx.builders import Builder from sphinx.domains.python import PyFunction, PyMethod from sphinx.errors import NoUri -from sphinx.locale import _ as sphinx_gettext, get_translation +from sphinx.locale import _ as sphinx_gettext from sphinx.util import logging from sphinx.util.docutils import SphinxDirective from sphinx.util.nodes import split_explicit_title @@ -36,8 +36,6 @@ # Deprecated in Sphinx 6.1, will be removed in Sphinx 8 from sphinx.util import status_iterator -_ = get_translation('sphinx') - ISSUE_URI = 'https://bugs.python.org/issue?@action=redirect&bpo=%s' GH_ISSUE_URI = 'https://github.com/python/cpython/issues/%s' @@ -100,14 +98,13 @@ class ImplementationDetail(Directive): final_argument_whitespace = True # This text is copied to templates/dummy.html - label_text = _('CPython implementation detail:') + label_text = sphinx_gettext('CPython implementation detail:') def run(self): self.assert_has_content() pnode = nodes.compound(classes=['impl-detail']) - label = sphinx_gettext(self.label_text) content = self.content - add_text = nodes.strong(label, label) + add_text = nodes.strong(self.label_text, self.label_text) self.state.nested_parse(content, self.content_offset, pnode) content = nodes.inline(pnode[0].rawsource, translatable=True) content.source = pnode[0].source @@ -236,9 +233,9 @@ class AuditEvent(Directive): final_argument_whitespace = True _label = [ - _("Raises an :ref:`auditing event ` {name} with no arguments."), - _("Raises an :ref:`auditing event ` {name} with argument {args}."), - _("Raises an :ref:`auditing event ` {name} with arguments {args}."), + sphinx_gettext("Raises an :ref:`auditing event ` {name} with no arguments."), + sphinx_gettext("Raises an :ref:`auditing event ` {name} with argument {args}."), + sphinx_gettext("Raises an :ref:`auditing event ` {name} with arguments {args}."), ] @property @@ -254,7 +251,7 @@ def run(self): else: args = [] - label = 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)) @@ -416,8 +413,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 = sphinx_gettext('Deprecated since version {deprecated}, will be removed in version {removed}') + _removed_label = sphinx_gettext('Deprecated since version {deprecated}, removed in version {removed}') def run(self): node = addnodes.versionmodified() @@ -433,7 +430,6 @@ def run(self): else: label = self._removed_label - label = 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],