Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
26 changes: 21 additions & 5 deletions python_docs_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import Any

from sphinx.application import Sphinx
from sphinx.util.typing import ExtensionMetadata

Expand All @@ -16,16 +18,30 @@
MESSAGE_CATALOG_NAME = "python-docs-theme"


def add_translation_to_context(
app: Sphinx,
pagename: str,
templatename: str,
context: dict[str, Any],
doctree: None,
) -> None:
theme_gettext = get_translation(MESSAGE_CATALOG_NAME)
sphinx_gettext = get_translation("sphinx")

def combined(message: str) -> str:
translation = theme_gettext(message)
if translation == message:
return sphinx_gettext(message)
return translation

context["_"] = context["gettext"] = context["ngettext"] = combined


def setup(app: Sphinx) -> ExtensionMetadata:
app.require_sphinx("7.3")

app.add_html_theme("python_docs_theme", str(THEME_PATH))
app.add_message_catalog(MESSAGE_CATALOG_NAME, LOCALE_DIR)

def add_translation_to_context(app, pagename, templatename, context, doctree):
_ = get_translation(MESSAGE_CATALOG_NAME)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the issue here is, we are loading just messages from python-docs-theme.po for HTML files.

context["_"] = context["gettext"] = context["ngettext"] = _

app.connect("html-page-context", add_translation_to_context)

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# Translators:
# Cristián Maureira-Fredes, 2025
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: python-docs-theme 2025.5\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# Translators:
# Inada Naoki <songofacandy@gmail.com>, 2025
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: python-docs-theme 2025.5\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# Translators:
# Stan Ulbrych, 2025
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: python-docs-theme 2025.5\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# Alexsey Batista da Silva, 2025
# Rafael Fontenelle <rffontenelle@gmail.com>, 2025
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: python-docs-theme 2025.5\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# Translators:
# Ege Akman, 2025
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: python-docs-theme 2025.5\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# Translators:
# 汇民 王 <whuim@qq.com>, 2025
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: python-docs-theme 2025.5\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# Translators:
# W. H. Wang <mattwang44@gmail.com>, 2025
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: python-docs-theme 2025.5\n"
Expand Down
Loading