Skip to content

Commit fee2ae0

Browse files
Fix translation of html pages (#263)
1 parent b87195c commit fee2ae0

File tree

8 files changed

+21
-12
lines changed

8 files changed

+21
-12
lines changed

python_docs_theme/__init__.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
TYPE_CHECKING = False
88
if TYPE_CHECKING:
9+
from typing import Any
10+
911
from sphinx.application import Sphinx
1012
from sphinx.util.typing import ExtensionMetadata
1113

@@ -16,16 +18,30 @@
1618
MESSAGE_CATALOG_NAME = "python-docs-theme"
1719

1820

21+
def add_translation_to_context(
22+
app: Sphinx,
23+
pagename: str,
24+
templatename: str,
25+
context: dict[str, Any],
26+
doctree: None,
27+
) -> None:
28+
theme_gettext = get_translation(MESSAGE_CATALOG_NAME)
29+
sphinx_gettext = get_translation("sphinx")
30+
31+
def combined(message: str) -> str:
32+
translation = theme_gettext(message)
33+
if translation == message:
34+
return sphinx_gettext(message)
35+
return translation
36+
37+
context["_"] = context["gettext"] = context["ngettext"] = combined
38+
39+
1940
def setup(app: Sphinx) -> ExtensionMetadata:
2041
app.require_sphinx("7.3")
2142

2243
app.add_html_theme("python_docs_theme", str(THEME_PATH))
2344
app.add_message_catalog(MESSAGE_CATALOG_NAME, LOCALE_DIR)
24-
25-
def add_translation_to_context(app, pagename, templatename, context, doctree):
26-
_ = get_translation(MESSAGE_CATALOG_NAME)
27-
context["_"] = context["gettext"] = context["ngettext"] = _
28-
2945
app.connect("html-page-context", add_translation_to_context)
3046

3147
return {

python_docs_theme/locale/es/LC_MESSAGES/python-docs-theme.po

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
# Translators:
88
# Cristián Maureira-Fredes, 2025
99
#
10-
#, fuzzy
1110
msgid ""
1211
msgstr ""
1312
"Project-Id-Version: python-docs-theme 2025.5\n"

python_docs_theme/locale/ja/LC_MESSAGES/python-docs-theme.po

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
# Translators:
88
# Inada Naoki <[email protected]>, 2025
99
#
10-
#, fuzzy
1110
msgid ""
1211
msgstr ""
1312
"Project-Id-Version: python-docs-theme 2025.5\n"

python_docs_theme/locale/pl/LC_MESSAGES/python-docs-theme.po

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
# Translators:
88
# Stan Ulbrych, 2025
99
#
10-
#, fuzzy
1110
msgid ""
1211
msgstr ""
1312
"Project-Id-Version: python-docs-theme 2025.5\n"

python_docs_theme/locale/pt_BR/LC_MESSAGES/python-docs-theme.po

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
# Alexsey Batista da Silva, 2025
99
# Rafael Fontenelle <[email protected]>, 2025
1010
#
11-
#, fuzzy
1211
msgid ""
1312
msgstr ""
1413
"Project-Id-Version: python-docs-theme 2025.5\n"

python_docs_theme/locale/tr/LC_MESSAGES/python-docs-theme.po

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
# Translators:
88
# Ege Akman, 2025
99
#
10-
#, fuzzy
1110
msgid ""
1211
msgstr ""
1312
"Project-Id-Version: python-docs-theme 2025.5\n"

python_docs_theme/locale/zh_CN/LC_MESSAGES/python-docs-theme.po

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
# Translators:
88
# 汇民 王 <[email protected]>, 2025
99
#
10-
#, fuzzy
1110
msgid ""
1211
msgstr ""
1312
"Project-Id-Version: python-docs-theme 2025.5\n"

python_docs_theme/locale/zh_TW/LC_MESSAGES/python-docs-theme.po

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
# Translators:
88
# W. H. Wang <[email protected]>, 2025
99
#
10-
#, fuzzy
1110
msgid ""
1211
msgstr ""
1312
"Project-Id-Version: python-docs-theme 2025.5\n"

0 commit comments

Comments
 (0)