Created
March 15, 2020 15:45
-
-
Save tk0miya/e2de1962f073d389251ba13e285b4336 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 551ad9efa5cc60a50e6f280e9aecdd12220693f1 Mon Sep 17 00:00:00 2001 | |
From: Takeshi KOMIYA <[email protected]> | |
Date: Mon, 16 Mar 2020 00:38:21 +0900 | |
Subject: [PATCH] doc: Fix messages in extensions are not translated | |
So far, custom extensions for python-doc have accessed internal data | |
structure of sphinx.locale module directly. But, it does not work at | |
present because the structure has changed since Sphinx-1.8 release. | |
This uses public translation APIs of Sphinx instead to get translated | |
messages. | |
refs: https://github.com/python/python-docs-ja/issues/24 | |
--- | |
Doc/tools/extensions/pyspecific.py | 22 +++++++++++----------- | |
1 file changed, 11 insertions(+), 11 deletions(-) | |
diff --git a/Doc/tools/extensions/pyspecific.py b/Doc/tools/extensions/pyspecific.py | |
index 2d9561241..14ccf833f 100644 | |
--- a/Doc/tools/extensions/pyspecific.py | |
+++ b/Doc/tools/extensions/pyspecific.py | |
@@ -26,7 +26,7 @@ try: | |
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 | |
@@ -37,6 +37,8 @@ from sphinx.domains.python import PyModulelevel, PyClassmember | |
import suspicious | |
+_ = get_translation('sphinx') | |
+ | |
ISSUE_URI = 'https://bugs.python.org/issue%s' | |
SOURCE_URI = 'https://github.com/python/cpython/tree/3.8/%s' | |
@@ -78,13 +80,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))) | |
@@ -133,9 +134,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 | |
@@ -151,7 +152,7 @@ class AuditEvent(Directive): | |
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)) | |
@@ -311,7 +312,7 @@ class DeprecatedRemoved(Directive): | |
final_argument_whitespace = True | |
option_spec = {} | |
- _label = 'Deprecated since version {deprecated}, will be removed in version {removed}' | |
+ _label = _('Deprecated since version {deprecated}, will be removed in version {removed}') | |
def run(self): | |
node = addnodes.versionmodified() | |
@@ -319,8 +320,7 @@ class DeprecatedRemoved(Directive): | |
node['type'] = 'deprecated-removed' | |
version = (self.arguments[0], self.arguments[1]) | |
node['version'] = version | |
- label = translators['sphinx'].gettext(self._label) | |
- text = label.format(deprecated=self.arguments[0], removed=self.arguments[1]) | |
+ text = self._label.format(deprecated=self.arguments[0], removed=self.arguments[1]) | |
if len(self.arguments) == 3: | |
inodes, messages = self.state.inline_text(self.arguments[2], | |
self.lineno+1) | |
-- | |
2.25.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment