From c75ef674c0dcf93cd23546cff50e37a6b74f5c88 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Thu, 7 Aug 2025 17:05:13 +0200 Subject: [PATCH 1/8] Commit --- .github/workflows/tests.yml | 6 +- .gitignore | 1 - babel_runner.py | 6 +- python_docs_theme/__init__.py | 14 ++ python_docs_theme/layout.html | 2 +- .../locales/pl_PL/LC_MESSAGES/messages.mo | Bin 0 -> 2231 bytes .../locales/pl_PL/LC_MESSAGES/messages.po | 125 ++++++++++++++++++ 7 files changed, 146 insertions(+), 8 deletions(-) create mode 100644 python_docs_theme/locales/pl_PL/LC_MESSAGES/messages.mo create mode 100644 python_docs_theme/locales/pl_PL/LC_MESSAGES/messages.po diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 23e6c7e6..33f57400 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -71,7 +71,7 @@ jobs: pip install -r requirements.txt - name: Remove locale file for testing shell: bash - run: rm -rf locales/pt_BR/ + run: rm -rf python_docs_theme/locales/pt_BR/ - run: python babel_runner.py extract - run: python babel_runner.py init -l pt_BR - run: python babel_runner.py update @@ -80,10 +80,10 @@ jobs: - run: python babel_runner.py compile -l pt_BR - name: Print .pot file shell: bash - run: cat locales/messages.pot + run: cat python_docs_theme/locales/messages.pot - name: Print .po file shell: bash - run: cat locales/pt_BR/LC_MESSAGES/messages.po + run: cat python_docs_theme/locales/pt_BR/LC_MESSAGES/messages.po - name: list files in locales dir shell: bash run: ls -R locales/ diff --git a/.gitignore b/.gitignore index 7bbc71c0..8962d423 100644 --- a/.gitignore +++ b/.gitignore @@ -47,7 +47,6 @@ coverage.xml .hypothesis/ # Translations -*.mo *.pot # Django stuff: diff --git a/babel_runner.py b/babel_runner.py index 0785ae2f..ef137115 100755 --- a/babel_runner.py +++ b/babel_runner.py @@ -1,4 +1,4 @@ -#!/usr/bin/venv python3 +#!/usr/bin/env python3 """Script for handling translations with Babel""" from __future__ import annotations @@ -15,9 +15,9 @@ # Global variables used by pybabel below (paths relative to PROJECT_DIR) DOMAIN = "messages" COPYRIGHT_HOLDER = "Python Software Foundation" -LOCALES_DIR = "locales" -POT_FILE = Path(LOCALES_DIR, f"{DOMAIN}.pot") SOURCE_DIR = "python_docs_theme" +LOCALES_DIR = f"{SOURCE_DIR}/locales" +POT_FILE = Path(LOCALES_DIR, f"{DOMAIN}.pot") MAPPING_FILE = ".babel.cfg" diff --git a/python_docs_theme/__init__.py b/python_docs_theme/__init__.py index 2336dc1e..4e74be40 100644 --- a/python_docs_theme/__init__.py +++ b/python_docs_theme/__init__.py @@ -1,5 +1,6 @@ from __future__ import annotations +import gettext from pathlib import Path TYPE_CHECKING = False @@ -12,9 +13,22 @@ THEME_PATH = Path(__file__).resolve().parent +def setup_translations(app): + translation = gettext.translation( + domain="messages", + localedir=str(THEME_PATH / "locales"), + languages=[app.config.language], + fallback=True, + ) + app.builder.templates.environment.install_gettext_translations( + translation, newstyle=True + ) + + def setup(app: Sphinx) -> ExtensionMetadata: app.require_sphinx("7.3") + app.connect("builder-inited", setup_translations) app.add_html_theme("python_docs_theme", str(THEME_PATH)) return { diff --git a/python_docs_theme/layout.html b/python_docs_theme/layout.html index a74517c9..37cd0aae 100644 --- a/python_docs_theme/layout.html +++ b/python_docs_theme/layout.html @@ -160,7 +160,7 @@

{{ _('Navigation') }}


{%- if last_updated %} - {% trans last_updated=last_updated|e %}Last updated on {{ last_updated }}.{% endtrans %} + {% trans last_updated=last_updated|e %}Last updated on %(last_updated)s.{% endtrans %} {%- endif %} {% if theme_issues_url %} {% trans %}Found a bug?{% endtrans %} diff --git a/python_docs_theme/locales/pl_PL/LC_MESSAGES/messages.mo b/python_docs_theme/locales/pl_PL/LC_MESSAGES/messages.mo new file mode 100644 index 0000000000000000000000000000000000000000..a6b076f4ab33cb30471d6e64b5045c97e91d180a GIT binary patch literal 2231 zcmbW1JB%Ae7{><)FM~h?6p*0!5_Bh@$gb^60w>@30=YcFmmIN!M1-)$yJLIo^~|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=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Babel 2.17.0\n" + +#: python_docs_theme/footerdonate.html:1 +msgid "The Python Software Foundation is a non-profit corporation." +msgstr "Python Software Foundation jest organizacją non-profit." + +#: python_docs_theme/footerdonate.html:2 +msgid "Please donate." +msgstr "Prosimy o wsparcie." + +#: python_docs_theme/layout.html:6 +msgid "Navigation" +msgstr "Nawigacja" + +#: python_docs_theme/layout.html:51 python_docs_theme/layout.html:111 +msgid "Quick search" +msgstr "Szybkie wyszukiwanie" + +#: python_docs_theme/layout.html:52 python_docs_theme/layout.html:112 +msgid "Go" +msgstr "Szukaj" + +#: python_docs_theme/layout.html:60 +msgid "Theme" +msgstr "Motyw" + +#: python_docs_theme/layout.html:62 +msgid "Auto" +msgstr "Auto" + +#: python_docs_theme/layout.html:63 +msgid "Light" +msgstr "Jasny" + +#: python_docs_theme/layout.html:64 +msgid "Dark" +msgstr "Ciemny" + +#: python_docs_theme/layout.html:96 +msgid "Menu" +msgstr "Menu" + +#: python_docs_theme/layout.html:142 +msgid "Copyright" +msgstr "Prawa autorskie" + +#: python_docs_theme/layout.html:147 +msgid "" +"This page is licensed under the Python Software Foundation License " +"Version 2." +msgstr "Ta strona jest licencjonowana na podstawie licencji Python Software " +"Foundation License Version 2." + +#: python_docs_theme/layout.html:149 +msgid "" +"Examples, recipes, and other code in the documentation are additionally " +"licensed under the Zero Clause BSD License." +msgstr "Przykłady, przepisy i inny kod w dokumentacji są dodatkowo udostępnione " +"na podstawie licencji Zero Clause BSD." + +#: python_docs_theme/layout.html:152 +#, python-format +msgid "" +"See History and License for more " +"information." +msgstr "" +"Zobacz Historię i licencję aby uzyskać " +"więcej informacji." + +#: python_docs_theme/layout.html:155 +#, python-format +msgid "Hosted on %(hosted_on)s." +msgstr "Hostowane na %(hosted_on)s." + +#: python_docs_theme/layout.html:163 +#, python-format +msgid "Last updated on %(last_updated)s." +msgstr "Ostatnia aktualizacja %(last_updated)." + +#: python_docs_theme/layout.html:166 +#, python-format +msgid "Found a bug?" +msgstr "Znalazłeś(-aś) błąd?" + +#: python_docs_theme/layout.html:170 +#, python-format +msgid "" +"Created using Sphinx " +"%(sphinx_version)s." +msgstr "" +"Stworzone za pomocą Sphinx " +"%(sphinx_version)s." + +#: python_docs_theme/static/copybutton.js:30 +#: python_docs_theme/static/copybutton.js:55 +msgid "Copy" +msgstr "Kopiuj" + +#: python_docs_theme/static/copybutton.js:31 +msgid "Copy to clipboard" +msgstr "Skopiuj do schowka" + +#: python_docs_theme/static/copybutton.js:53 +msgid "Copied!" +msgstr "Skopiowano!" From 6377d64cc2ec01ad731f60fda079787544b22c8a Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Thu, 7 Aug 2025 17:09:35 +0200 Subject: [PATCH 2/8] Remove CI step --- .github/workflows/tests.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 33f57400..7f80f8c7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -84,6 +84,3 @@ jobs: - name: Print .po file shell: bash run: cat python_docs_theme/locales/pt_BR/LC_MESSAGES/messages.po - - name: list files in locales dir - shell: bash - run: ls -R locales/ From 9dede6681f6c9c3dc14adca365b5020150fc5c72 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Thu, 7 Aug 2025 19:18:51 +0200 Subject: [PATCH 3/8] Fixup --- python_docs_theme/layout.html | 2 +- .../locales/pl_PL/LC_MESSAGES/messages.mo | Bin 2231 -> 2232 bytes .../locales/pl_PL/LC_MESSAGES/messages.po | 12 +++++++----- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/python_docs_theme/layout.html b/python_docs_theme/layout.html index 37cd0aae..a74517c9 100644 --- a/python_docs_theme/layout.html +++ b/python_docs_theme/layout.html @@ -160,7 +160,7 @@

{{ _('Navigation') }}


{%- if last_updated %} - {% trans last_updated=last_updated|e %}Last updated on %(last_updated)s.{% endtrans %} + {% trans last_updated=last_updated|e %}Last updated on {{ last_updated }}.{% endtrans %} {%- endif %} {% if theme_issues_url %} {% trans %}Found a bug?{% endtrans %} diff --git a/python_docs_theme/locales/pl_PL/LC_MESSAGES/messages.mo b/python_docs_theme/locales/pl_PL/LC_MESSAGES/messages.mo index a6b076f4ab33cb30471d6e64b5045c97e91d180a..55ed88958b194ae6b278bd4032960ca6349af40f 100644 GIT binary patch delta 107 zcmdlkxI=J*4x_I+0|P?{I|BnNkgfsJEI_&mNOJ<|b|5Vbq$dJt5g@%3NXG!_T|n9b mNQ-ko^aTLvL?AzGb0wnyGmE8_f#v32mN!g{#hWYH?HB>h3=b6m delta 105 zcmdlXxLt6A4x_Ic0|P?{I|BnNkgf*OEI_&uNOJ<|HXtnwq$dDr5g@$;NXG!_oj}?G kNQ-em^!WqnL?AzOb0wnyGmEK}q2cCUmN!hBtJv)r0j@a?jQ{`u diff --git a/python_docs_theme/locales/pl_PL/LC_MESSAGES/messages.po b/python_docs_theme/locales/pl_PL/LC_MESSAGES/messages.po index 42c52c09..759a529d 100644 --- a/python_docs_theme/locales/pl_PL/LC_MESSAGES/messages.po +++ b/python_docs_theme/locales/pl_PL/LC_MESSAGES/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: python-docs-theme 2025.5\n" "Report-Msgid-Bugs-To: https://github.com/python/python-docs-theme/issues\n" -"POT-Creation-Date: 2025-08-07 15:11+0200\n" +"POT-Creation-Date: 2025-08-07 19:09+0200\n" "PO-Revision-Date: 2025-08-07 15:11+0200\n" "Last-Translator: Stan Ulbrych \n" "Language: pl_PL\n" @@ -18,7 +18,7 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" -"Generated-By: Babel 2.17.0\n" +"Generated-By: Babel 2.16.0\n" #: python_docs_theme/footerdonate.html:1 msgid "The Python Software Foundation is a non-profit corporation." @@ -68,14 +68,16 @@ msgstr "Prawa autorskie" msgid "" "This page is licensed under the Python Software Foundation License " "Version 2." -msgstr "Ta strona jest licencjonowana na podstawie licencji Python Software " +msgstr "" +"Ta strona jest licencjonowana na podstawie licencji Python Software " "Foundation License Version 2." #: python_docs_theme/layout.html:149 msgid "" "Examples, recipes, and other code in the documentation are additionally " "licensed under the Zero Clause BSD License." -msgstr "Przykłady, przepisy i inny kod w dokumentacji są dodatkowo udostępnione " +msgstr "" +"Przykłady, przepisy i inny kod w dokumentacji są dodatkowo udostępnione " "na podstawie licencji Zero Clause BSD." #: python_docs_theme/layout.html:152 @@ -95,7 +97,7 @@ msgstr "Hostowane na %(hosted_on)s." #: python_docs_theme/layout.html:163 #, python-format msgid "Last updated on %(last_updated)s." -msgstr "Ostatnia aktualizacja %(last_updated)." +msgstr "Ostatnia aktualizacja %(last_updated)s." #: python_docs_theme/layout.html:166 #, python-format From 49f99d8dfb5a712580e49ffe2361767d6105ad0f Mon Sep 17 00:00:00 2001 From: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Date: Sat, 9 Aug 2025 07:46:12 +0200 Subject: [PATCH 4/8] Apply suggestions from Maciek Co-authored-by: Maciej Olko --- python_docs_theme/__init__.py | 2 +- .../locales/pl_PL/LC_MESSAGES/messages.po | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/python_docs_theme/__init__.py b/python_docs_theme/__init__.py index 4e74be40..d8f7b682 100644 --- a/python_docs_theme/__init__.py +++ b/python_docs_theme/__init__.py @@ -16,7 +16,7 @@ def setup_translations(app): translation = gettext.translation( domain="messages", - localedir=str(THEME_PATH / "locales"), + localedir=os.fspath(THEME_PATH / "locales"), languages=[app.config.language], fallback=True, ) diff --git a/python_docs_theme/locales/pl_PL/LC_MESSAGES/messages.po b/python_docs_theme/locales/pl_PL/LC_MESSAGES/messages.po index 759a529d..f594f94c 100644 --- a/python_docs_theme/locales/pl_PL/LC_MESSAGES/messages.po +++ b/python_docs_theme/locales/pl_PL/LC_MESSAGES/messages.po @@ -46,15 +46,15 @@ msgstr "Motyw" #: python_docs_theme/layout.html:62 msgid "Auto" -msgstr "Auto" +msgstr "auto" #: python_docs_theme/layout.html:63 msgid "Light" -msgstr "Jasny" +msgstr "jasny" #: python_docs_theme/layout.html:64 msgid "Dark" -msgstr "Ciemny" +msgstr "ciemny" #: python_docs_theme/layout.html:96 msgid "Menu" @@ -69,16 +69,16 @@ msgid "" "This page is licensed under the Python Software Foundation License " "Version 2." msgstr "" -"Ta strona jest licencjonowana na podstawie licencji Python Software " -"Foundation License Version 2." +"Ta strona jest objęta licencją Python Software " +"Foundation w wersji 2." #: python_docs_theme/layout.html:149 msgid "" "Examples, recipes, and other code in the documentation are additionally " "licensed under the Zero Clause BSD License." msgstr "" -"Przykłady, przepisy i inny kod w dokumentacji są dodatkowo udostępnione " -"na podstawie licencji Zero Clause BSD." +"Przykłady, przepisy i inny kod w dokumentacji są dodatkowo objęte " +"licencją Zero Clause BSD." #: python_docs_theme/layout.html:152 #, python-format From 7c1c487364e7973cfe7b35b5912a4638e52c1ed2 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Fri, 29 Aug 2025 15:56:57 +0100 Subject: [PATCH 5/8] Fixup --- python_docs_theme/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python_docs_theme/__init__.py b/python_docs_theme/__init__.py index 4e74be40..4ec34f50 100644 --- a/python_docs_theme/__init__.py +++ b/python_docs_theme/__init__.py @@ -1,6 +1,7 @@ from __future__ import annotations import gettext +import os from pathlib import Path TYPE_CHECKING = False @@ -16,7 +17,7 @@ def setup_translations(app): translation = gettext.translation( domain="messages", - localedir=str(THEME_PATH / "locales"), + localedir=os.fspath(THEME_PATH / "locales"), languages=[app.config.language], fallback=True, ) From a69099321b5732824685880e52dfc00aa0496574 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Tue, 2 Sep 2025 20:56:18 +0100 Subject: [PATCH 6/8] Review --- .github/workflows/tests.yml | 6 ++-- babel_runner.py | 33 ++++++++++++------ python_docs_theme/__init__.py | 33 ++++++++---------- .../pl/LC_MESSAGES/python-docs-theme.mo} | Bin 2232 -> 2182 bytes 4 files changed, 39 insertions(+), 33 deletions(-) rename python_docs_theme/{locales/pl_PL/LC_MESSAGES/messages.mo => locale/pl/LC_MESSAGES/python-docs-theme.mo} (59%) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7f80f8c7..d75bd25d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -71,7 +71,7 @@ jobs: pip install -r requirements.txt - name: Remove locale file for testing shell: bash - run: rm -rf python_docs_theme/locales/pt_BR/ + run: rm -rf python_docs_theme/locale/pt_BR/ - run: python babel_runner.py extract - run: python babel_runner.py init -l pt_BR - run: python babel_runner.py update @@ -80,7 +80,7 @@ jobs: - run: python babel_runner.py compile -l pt_BR - name: Print .pot file shell: bash - run: cat python_docs_theme/locales/messages.pot + run: cat python_docs_theme/locale/messages.pot - name: Print .po file shell: bash - run: cat python_docs_theme/locales/pt_BR/LC_MESSAGES/messages.po + run: cat python_docs_theme/locale/pt_BR/LC_MESSAGES/messages.po diff --git a/babel_runner.py b/babel_runner.py index ef137115..39c691c5 100755 --- a/babel_runner.py +++ b/babel_runner.py @@ -1,5 +1,5 @@ -#!/usr/bin/env python3 """Script for handling translations with Babel""" + from __future__ import annotations import argparse @@ -8,18 +8,18 @@ import tomllib from pathlib import Path -PROJECT_DIR = Path(__file__).resolve().parent -PYPROJECT_TOML = PROJECT_DIR / "pyproject.toml" -INIT_PY = PROJECT_DIR / "python_docs_theme" / "__init__.py" - # Global variables used by pybabel below (paths relative to PROJECT_DIR) -DOMAIN = "messages" +DOMAIN = "python-docs-theme" COPYRIGHT_HOLDER = "Python Software Foundation" SOURCE_DIR = "python_docs_theme" -LOCALES_DIR = f"{SOURCE_DIR}/locales" -POT_FILE = Path(LOCALES_DIR, f"{DOMAIN}.pot") MAPPING_FILE = ".babel.cfg" +PROJECT_DIR = Path(__file__).resolve().parent +PYPROJECT_TOML = PROJECT_DIR / "pyproject.toml" +INIT_PY = PROJECT_DIR / SOURCE_DIR / "__init__.py" +LOCALES_DIR = f"{SOURCE_DIR}/locale" +POT_FILE = Path(LOCALES_DIR, f"{DOMAIN}.pot") + def get_project_info() -> dict: """Retrieve project's info to populate the message catalog template""" @@ -75,13 +75,24 @@ def init_locale(locale: str) -> None: if pofile.exists(): print(f"There is already a message catalog for locale {locale}, skipping.") return - cmd = ["pybabel", "init", "-i", POT_FILE, "-d", LOCALES_DIR, "-l", locale] + cmd = [ + "pybabel", + "init", + "-i", + POT_FILE, + "-d", + LOCALES_DIR, + "-D", + DOMAIN, + "-l", + locale, + ] subprocess.run(cmd, cwd=PROJECT_DIR, check=True) def update_catalogs(locale: str) -> None: """Update translations from existing message catalogs""" - cmd = ["pybabel", "update", "-i", POT_FILE, "-d", LOCALES_DIR] + cmd = ["pybabel", "update", "-i", POT_FILE, "-d", LOCALES_DIR, "-D", DOMAIN] if locale: cmd.extend(["-l", locale]) subprocess.run(cmd, cwd=PROJECT_DIR, check=True) @@ -89,7 +100,7 @@ def update_catalogs(locale: str) -> None: def compile_catalogs(locale: str) -> None: """Compile existing message catalogs""" - cmd = ["pybabel", "compile", "-d", LOCALES_DIR] + cmd = ["pybabel", "compile", "-d", LOCALES_DIR, "-D", DOMAIN] if locale: cmd.extend(["-l", locale]) subprocess.run(cmd, cwd=PROJECT_DIR, check=True) diff --git a/python_docs_theme/__init__.py b/python_docs_theme/__init__.py index 4ec34f50..300dcdd0 100644 --- a/python_docs_theme/__init__.py +++ b/python_docs_theme/__init__.py @@ -1,36 +1,31 @@ from __future__ import annotations -import gettext -import os from pathlib import Path +from sphinx.locale import get_translation + TYPE_CHECKING = False if TYPE_CHECKING: - from sphinx.application import Sphinx - from sphinx.util.typing import ExtensionMetadata + from sphinx.application import Sphinx # noqa: F401 + from sphinx.util.typing import ExtensionMetadata # noqa: F401 __version__ = "2025.5" THEME_PATH = Path(__file__).resolve().parent +LOCALE_DIR = THEME_PATH / "locale" +MESSAGE_CATALOG_NAME = "python-docs-theme" -def setup_translations(app): - translation = gettext.translation( - domain="messages", - localedir=os.fspath(THEME_PATH / "locales"), - languages=[app.config.language], - fallback=True, - ) - app.builder.templates.environment.install_gettext_translations( - translation, newstyle=True - ) - - -def setup(app: Sphinx) -> ExtensionMetadata: +def setup(app): app.require_sphinx("7.3") - - app.connect("builder-inited", setup_translations) 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 { "version": __version__, diff --git a/python_docs_theme/locales/pl_PL/LC_MESSAGES/messages.mo b/python_docs_theme/locale/pl/LC_MESSAGES/python-docs-theme.mo similarity index 59% rename from python_docs_theme/locales/pl_PL/LC_MESSAGES/messages.mo rename to python_docs_theme/locale/pl/LC_MESSAGES/python-docs-theme.mo index 55ed88958b194ae6b278bd4032960ca6349af40f..cbdb4841fc666eac10ad53a421f63e70dfde7d3e 100644 GIT binary patch delta 285 zcmdlX*d{pPO#N#{28J)p3=B353=9ug85mfAv@9C~12>RX0@6Ulpa&#`fV3%)<_FRq zKspjgM*wLcV%P*E;(_!|C|{DDfk7I`R{+xLK-vaK1C3@#0n#Azvw$=wkj`gk&|?q= zGAe-rB0#zqNXG!_ML^mDNdE`YAdMCr3=Hl-+HP|tV=l80mrr6|dTC;Ms%}VXVy=}! zLC)rXEUJu*iIY{>rZ6T?-pS@Hn4gq&WM)aKLQZCKYF={Ik=Dub?6HhllWW;uK;;sV VS?0MbCjU;-qBfV4G`<_FS# zKspjg#{p>|V%PyB3W4-~DBqBsfk7I`w*b=WKsp3S1C3^=0n#Azn}9SYkZxyZFk}!0 zGA05AM1b^CARPmwcL8Y&AT7=T(HH=v6M_6NAU*j$tHS0vj9$zV@c}+uK8bnhrHSdO zx*@5FxmF4VIY7b9KUh>58679fu}xugp1hgOS-CVNzqsVc%!0hk{Jd0!yhMe9{FLI7 x#PZBkg`CXf)V$=Z%*pKRv5a1mQ`ujrLWT14^2-x}YOyL;nEanzdh$bNVE{&6MHT=6 From 9c017a1fafa5247ff954fd031b9c47c3123eab20 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Tue, 2 Sep 2025 21:03:26 +0100 Subject: [PATCH 7/8] Fixup --- .github/workflows/tests.yml | 4 ++-- python_docs_theme/__init__.py | 7 ++++--- .../pl/LC_MESSAGES/python-docs-theme.po} | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) rename python_docs_theme/{locales/pl_PL/LC_MESSAGES/messages.po => locale/pl/LC_MESSAGES/python-docs-theme.po} (98%) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d75bd25d..dfe7ce3f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -80,7 +80,7 @@ jobs: - run: python babel_runner.py compile -l pt_BR - name: Print .pot file shell: bash - run: cat python_docs_theme/locale/messages.pot + run: cat python_docs_theme/locale/python-docs-theme.pot - name: Print .po file shell: bash - run: cat python_docs_theme/locale/pt_BR/LC_MESSAGES/messages.po + run: cat python_docs_theme/locale/pt_BR/LC_MESSAGES/python-docs-theme.po diff --git a/python_docs_theme/__init__.py b/python_docs_theme/__init__.py index 300dcdd0..6b80ad0a 100644 --- a/python_docs_theme/__init__.py +++ b/python_docs_theme/__init__.py @@ -6,8 +6,8 @@ TYPE_CHECKING = False if TYPE_CHECKING: - from sphinx.application import Sphinx # noqa: F401 - from sphinx.util.typing import ExtensionMetadata # noqa: F401 + from sphinx.application import Sphinx + from sphinx.util.typing import ExtensionMetadata __version__ = "2025.5" @@ -16,8 +16,9 @@ MESSAGE_CATALOG_NAME = "python-docs-theme" -def setup(app): +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) diff --git a/python_docs_theme/locales/pl_PL/LC_MESSAGES/messages.po b/python_docs_theme/locale/pl/LC_MESSAGES/python-docs-theme.po similarity index 98% rename from python_docs_theme/locales/pl_PL/LC_MESSAGES/messages.po rename to python_docs_theme/locale/pl/LC_MESSAGES/python-docs-theme.po index f594f94c..cb74d912 100644 --- a/python_docs_theme/locales/pl_PL/LC_MESSAGES/messages.po +++ b/python_docs_theme/locale/pl/LC_MESSAGES/python-docs-theme.po @@ -11,8 +11,8 @@ msgstr "" "POT-Creation-Date: 2025-08-07 19:09+0200\n" "PO-Revision-Date: 2025-08-07 15:11+0200\n" "Last-Translator: Stan Ulbrych \n" -"Language: pl_PL\n" -"Language-Team: pl_PL \n" +"Language: pl\n" +"Language-Team: pl \n" "Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && " "(n%100<10 || n%100>=20) ? 1 : 2);\n" "MIME-Version: 1.0\n" From 151cfe9b73daf30cdba05719a23959417c115c0c Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Wed, 3 Sep 2025 16:15:07 +0100 Subject: [PATCH 8/8] Review --- .github/workflows/pypi-package.yml | 7 +++++++ .gitignore | 1 + babel_runner.py | 4 ++-- .../locale/pl/LC_MESSAGES/python-docs-theme.mo | Bin 2182 -> 0 bytes 4 files changed, 10 insertions(+), 2 deletions(-) delete mode 100644 python_docs_theme/locale/pl/LC_MESSAGES/python-docs-theme.mo diff --git a/.github/workflows/pypi-package.yml b/.github/workflows/pypi-package.yml index 744d49bd..44a58230 100644 --- a/.github/workflows/pypi-package.yml +++ b/.github/workflows/pypi-package.yml @@ -22,6 +22,13 @@ jobs: steps: - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + + - name: Compile translations + run: | + pip install --upgrade pip + pip install -r requirements.txt + python babel_runner.py compile - uses: hynek/build-and-inspect-python-package@v2 diff --git a/.gitignore b/.gitignore index 8962d423..7bbc71c0 100644 --- a/.gitignore +++ b/.gitignore @@ -47,6 +47,7 @@ coverage.xml .hypothesis/ # Translations +*.mo *.pot # Django stuff: diff --git a/babel_runner.py b/babel_runner.py index 39c691c5..677f6da2 100755 --- a/babel_runner.py +++ b/babel_runner.py @@ -15,9 +15,9 @@ MAPPING_FILE = ".babel.cfg" PROJECT_DIR = Path(__file__).resolve().parent -PYPROJECT_TOML = PROJECT_DIR / "pyproject.toml" +PYPROJECT_TOML = Path(PROJECT_DIR, "pyproject.toml") INIT_PY = PROJECT_DIR / SOURCE_DIR / "__init__.py" -LOCALES_DIR = f"{SOURCE_DIR}/locale" +LOCALES_DIR = Path(f"{SOURCE_DIR}", "locale") POT_FILE = Path(LOCALES_DIR, f"{DOMAIN}.pot") diff --git a/python_docs_theme/locale/pl/LC_MESSAGES/python-docs-theme.mo b/python_docs_theme/locale/pl/LC_MESSAGES/python-docs-theme.mo deleted file mode 100644 index cbdb4841fc666eac10ad53a421f63e70dfde7d3e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2182 zcmbW1JB%Ae7{><)FM~h?#6y7e<)jNfkzLyt4lX|X0=Ybej~uZ<5FuIP-LXCPdS^8= zo6TCGi4;*$QbcJG1xQFV>7b$DuA`wwLNruqDCj8QKWitBq9jOI>;3J_d^7VsX8ynJ z-}eQ>?|J-R!T)F1xb1i80mdq5e+upczXKlyug}{*fX|@)BltM@3wRFvbw2Jt$e2O< zFo=hJgV&4Tx8MQrC-7nL574cD11y1mf=_{egHM8`hZt*tFMu0h2)cP+g4^KN;0^5g z7uZ1icMQ7qUVVhIC%`2T5A*Tb53YevgQvld!H+;Z>^fdu@cViDB?S92+62A^HbA#; z2)gx0po?39&w@Gl9QZl-3HTMb4*mnWdFzicb_(1CS%cG1i+*!yxon4GBD&I;RG4n6 zqZPBXc~YfuNSu15LJ&yI6FW+yK4 zNfHTjh_nb~;yyV1R0u&+ph7`1CNv1krV|lcZZVy>7R19)x(1J;oFW;B*fusBX483FNz<3>1r<;d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