diff --git a/python_docs_theme/__init__.py b/python_docs_theme/__init__.py index d9281ff..875206b 100644 --- a/python_docs_theme/__init__.py +++ b/python_docs_theme/__init__.py @@ -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 @@ -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) - context["_"] = context["gettext"] = context["ngettext"] = _ - app.connect("html-page-context", add_translation_to_context) return { diff --git a/python_docs_theme/locale/es/LC_MESSAGES/python-docs-theme.po b/python_docs_theme/locale/es/LC_MESSAGES/python-docs-theme.po index 34fc30e..5ac9ab3 100644 --- a/python_docs_theme/locale/es/LC_MESSAGES/python-docs-theme.po +++ b/python_docs_theme/locale/es/LC_MESSAGES/python-docs-theme.po @@ -7,7 +7,6 @@ # Translators: # Cristián Maureira-Fredes, 2025 # -#, fuzzy msgid "" msgstr "" "Project-Id-Version: python-docs-theme 2025.5\n" diff --git a/python_docs_theme/locale/ja/LC_MESSAGES/python-docs-theme.po b/python_docs_theme/locale/ja/LC_MESSAGES/python-docs-theme.po index dfea857..f0683c2 100644 --- a/python_docs_theme/locale/ja/LC_MESSAGES/python-docs-theme.po +++ b/python_docs_theme/locale/ja/LC_MESSAGES/python-docs-theme.po @@ -7,7 +7,6 @@ # Translators: # Inada Naoki , 2025 # -#, fuzzy msgid "" msgstr "" "Project-Id-Version: python-docs-theme 2025.5\n" diff --git a/python_docs_theme/locale/pl/LC_MESSAGES/python-docs-theme.po b/python_docs_theme/locale/pl/LC_MESSAGES/python-docs-theme.po index 461c4c9..5249a26 100644 --- a/python_docs_theme/locale/pl/LC_MESSAGES/python-docs-theme.po +++ b/python_docs_theme/locale/pl/LC_MESSAGES/python-docs-theme.po @@ -7,7 +7,6 @@ # Translators: # Stan Ulbrych, 2025 # -#, fuzzy msgid "" msgstr "" "Project-Id-Version: python-docs-theme 2025.5\n" diff --git a/python_docs_theme/locale/pt_BR/LC_MESSAGES/python-docs-theme.po b/python_docs_theme/locale/pt_BR/LC_MESSAGES/python-docs-theme.po index 2ce0936..1006ae9 100644 --- a/python_docs_theme/locale/pt_BR/LC_MESSAGES/python-docs-theme.po +++ b/python_docs_theme/locale/pt_BR/LC_MESSAGES/python-docs-theme.po @@ -8,7 +8,6 @@ # Alexsey Batista da Silva, 2025 # Rafael Fontenelle , 2025 # -#, fuzzy msgid "" msgstr "" "Project-Id-Version: python-docs-theme 2025.5\n" diff --git a/python_docs_theme/locale/tr/LC_MESSAGES/python-docs-theme.po b/python_docs_theme/locale/tr/LC_MESSAGES/python-docs-theme.po index 90afb86..f79742f 100644 --- a/python_docs_theme/locale/tr/LC_MESSAGES/python-docs-theme.po +++ b/python_docs_theme/locale/tr/LC_MESSAGES/python-docs-theme.po @@ -7,7 +7,6 @@ # Translators: # Ege Akman, 2025 # -#, fuzzy msgid "" msgstr "" "Project-Id-Version: python-docs-theme 2025.5\n" diff --git a/python_docs_theme/locale/zh_CN/LC_MESSAGES/python-docs-theme.po b/python_docs_theme/locale/zh_CN/LC_MESSAGES/python-docs-theme.po index 8fb52a4..73cc293 100644 --- a/python_docs_theme/locale/zh_CN/LC_MESSAGES/python-docs-theme.po +++ b/python_docs_theme/locale/zh_CN/LC_MESSAGES/python-docs-theme.po @@ -7,7 +7,6 @@ # Translators: # 汇民 王 , 2025 # -#, fuzzy msgid "" msgstr "" "Project-Id-Version: python-docs-theme 2025.5\n" diff --git a/python_docs_theme/locale/zh_TW/LC_MESSAGES/python-docs-theme.po b/python_docs_theme/locale/zh_TW/LC_MESSAGES/python-docs-theme.po index 719074c..c65766b 100644 --- a/python_docs_theme/locale/zh_TW/LC_MESSAGES/python-docs-theme.po +++ b/python_docs_theme/locale/zh_TW/LC_MESSAGES/python-docs-theme.po @@ -7,7 +7,6 @@ # Translators: # W. H. Wang , 2025 # -#, fuzzy msgid "" msgstr "" "Project-Id-Version: python-docs-theme 2025.5\n"