Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4f43ade

Browse files
Enable theme translation (#246)
Co-authored-by: Maciej Olko <maciej.olko@gmail.com>
1 parent7c4e6c2 commit4f43ade

File tree

5 files changed

+170
-17
lines changed

5 files changed

+170
-17
lines changed

‎.github/workflows/pypi-package.yml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ jobs:
2222

2323
steps:
2424
-uses:actions/checkout@v5
25+
-uses:actions/setup-python@v5
26+
27+
-name:Compile translations
28+
run:|
29+
pip install --upgrade pip
30+
pip install -r requirements.txt
31+
python babel_runner.py compile
2532
2633
-uses:hynek/build-and-inspect-python-package@v2
2734

‎.github/workflows/tests.yml‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
pip install -r requirements.txt
7272
-name:Remove locale file for testing
7373
shell:bash
74-
run:rm -rflocales/pt_BR/
74+
run:rm -rfpython_docs_theme/locale/pt_BR/
7575
-run:python babel_runner.py extract
7676
-run:python babel_runner.py init -l pt_BR
7777
-run:python babel_runner.py update
@@ -80,10 +80,7 @@ jobs:
8080
-run:python babel_runner.py compile -l pt_BR
8181
-name:Print .pot file
8282
shell:bash
83-
run:catlocales/messages.pot
83+
run:catpython_docs_theme/locale/python-docs-theme.pot
8484
-name:Print .po file
8585
shell:bash
86-
run:cat locales/pt_BR/LC_MESSAGES/messages.po
87-
-name:list files in locales dir
88-
shell:bash
89-
run:ls -R locales/
86+
run:cat python_docs_theme/locale/pt_BR/LC_MESSAGES/python-docs-theme.po

‎babel_runner.py‎

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#!/usr/bin/venv python3
21
"""Script for handling translations with Babel"""
2+
33
from __future__importannotations
44

55
importargparse
@@ -8,18 +8,18 @@
88
importtomllib
99
frompathlibimportPath
1010

11-
PROJECT_DIR=Path(__file__).resolve().parent
12-
PYPROJECT_TOML=PROJECT_DIR/"pyproject.toml"
13-
INIT_PY=PROJECT_DIR/"python_docs_theme"/"__init__.py"
14-
1511
# Global variables used by pybabel below (paths relative to PROJECT_DIR)
16-
DOMAIN="messages"
12+
DOMAIN="python-docs-theme"
1713
COPYRIGHT_HOLDER="Python Software Foundation"
18-
LOCALES_DIR="locales"
19-
POT_FILE=Path(LOCALES_DIR,f"{DOMAIN}.pot")
2014
SOURCE_DIR="python_docs_theme"
2115
MAPPING_FILE=".babel.cfg"
2216

17+
PROJECT_DIR=Path(__file__).resolve().parent
18+
PYPROJECT_TOML=Path(PROJECT_DIR,"pyproject.toml")
19+
INIT_PY=PROJECT_DIR/SOURCE_DIR/"__init__.py"
20+
LOCALES_DIR=Path(f"{SOURCE_DIR}","locale")
21+
POT_FILE=Path(LOCALES_DIR,f"{DOMAIN}.pot")
22+
2323

2424
defget_project_info()->dict:
2525
"""Retrieve project's info to populate the message catalog template"""
@@ -75,21 +75,32 @@ def init_locale(locale: str) -> None:
7575
ifpofile.exists():
7676
print(f"There is already a message catalog for locale{locale}, skipping.")
7777
return
78-
cmd= ["pybabel","init","-i",POT_FILE,"-d",LOCALES_DIR,"-l",locale]
78+
cmd= [
79+
"pybabel",
80+
"init",
81+
"-i",
82+
POT_FILE,
83+
"-d",
84+
LOCALES_DIR,
85+
"-D",
86+
DOMAIN,
87+
"-l",
88+
locale,
89+
]
7990
subprocess.run(cmd,cwd=PROJECT_DIR,check=True)
8091

8192

8293
defupdate_catalogs(locale:str)->None:
8394
"""Update translations from existing message catalogs"""
84-
cmd= ["pybabel","update","-i",POT_FILE,"-d",LOCALES_DIR]
95+
cmd= ["pybabel","update","-i",POT_FILE,"-d",LOCALES_DIR,"-D",DOMAIN]
8596
iflocale:
8697
cmd.extend(["-l",locale])
8798
subprocess.run(cmd,cwd=PROJECT_DIR,check=True)
8899

89100

90101
defcompile_catalogs(locale:str)->None:
91102
"""Compile existing message catalogs"""
92-
cmd= ["pybabel","compile","-d",LOCALES_DIR]
103+
cmd= ["pybabel","compile","-d",LOCALES_DIR,"-D",DOMAIN]
93104
iflocale:
94105
cmd.extend(["-l",locale])
95106
subprocess.run(cmd,cwd=PROJECT_DIR,check=True)

‎python_docs_theme/__init__.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
frompathlibimportPath
44

5+
fromsphinx.localeimportget_translation
6+
57
TYPE_CHECKING=False
68
ifTYPE_CHECKING:
79
fromsphinx.applicationimportSphinx
@@ -10,12 +12,21 @@
1012
__version__="2025.5"
1113

1214
THEME_PATH=Path(__file__).resolve().parent
15+
LOCALE_DIR=THEME_PATH/"locale"
16+
MESSAGE_CATALOG_NAME="python-docs-theme"
1317

1418

1519
defsetup(app:Sphinx)->ExtensionMetadata:
1620
app.require_sphinx("7.3")
1721

1822
app.add_html_theme("python_docs_theme",str(THEME_PATH))
23+
app.add_message_catalog(MESSAGE_CATALOG_NAME,LOCALE_DIR)
24+
25+
defadd_translation_to_context(app,pagename,templatename,context,doctree):
26+
_=get_translation(MESSAGE_CATALOG_NAME)
27+
context["_"]=context["gettext"]=context["ngettext"]=_
28+
29+
app.connect("html-page-context",add_translation_to_context)
1930

2031
return {
2132
"version":__version__,
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Polish (Poland) translations for python-docs-theme.
2+
# Copyright (C) 2025 Python Software Foundation
3+
# This file is distributed under the same license as the python-docs-theme
4+
# project.
5+
# Stan Ulbrych, 2025.
6+
#
7+
msgid ""
8+
msgstr ""
9+
"Project-Id-Version:python-docs-theme 2025.5\n"
10+
"Report-Msgid-Bugs-To:https://github.com/python/python-docs-theme/issues\n"
11+
"POT-Creation-Date:2025-08-07 19:09+0200\n"
12+
"PO-Revision-Date:2025-08-07 15:11+0200\n"
13+
"Last-Translator:Stan Ulbrych \n"
14+
"Language:pl\n"
15+
"Language-Team:pl <LL@li.org>\n"
16+
"Plural-Forms:nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 &&"
17+
"(n%100<10 || n%100>=20) ? 1 : 2);\n"
18+
"MIME-Version:1.0\n"
19+
"Content-Type:text/plain; charset=utf-8\n"
20+
"Content-Transfer-Encoding:8bit\n"
21+
"Generated-By:Babel 2.16.0\n"
22+
23+
#:python_docs_theme/footerdonate.html:1
24+
msgid"The Python Software Foundation is a non-profit corporation."
25+
msgstr"Python Software Foundation jest organizacją non-profit."
26+
27+
#:python_docs_theme/footerdonate.html:2
28+
msgid"Please donate."
29+
msgstr"Prosimy o wsparcie."
30+
31+
#:python_docs_theme/layout.html:6
32+
msgid"Navigation"
33+
msgstr"Nawigacja"
34+
35+
#:python_docs_theme/layout.html:51python_docs_theme/layout.html:111
36+
msgid"Quick search"
37+
msgstr"Szybkie wyszukiwanie"
38+
39+
#:python_docs_theme/layout.html:52python_docs_theme/layout.html:112
40+
msgid"Go"
41+
msgstr"Szukaj"
42+
43+
#:python_docs_theme/layout.html:60
44+
msgid"Theme"
45+
msgstr"Motyw"
46+
47+
#:python_docs_theme/layout.html:62
48+
msgid"Auto"
49+
msgstr"auto"
50+
51+
#:python_docs_theme/layout.html:63
52+
msgid"Light"
53+
msgstr"jasny"
54+
55+
#:python_docs_theme/layout.html:64
56+
msgid"Dark"
57+
msgstr"ciemny"
58+
59+
#:python_docs_theme/layout.html:96
60+
msgid"Menu"
61+
msgstr"Menu"
62+
63+
#:python_docs_theme/layout.html:142
64+
msgid"Copyright"
65+
msgstr"Prawa autorskie"
66+
67+
#:python_docs_theme/layout.html:147
68+
msgid""
69+
"This page is licensed under the Python Software Foundation License "
70+
"Version 2."
71+
msgstr""
72+
"Ta strona jest objęta licencją Python Software "
73+
"Foundation w wersji 2."
74+
75+
#:python_docs_theme/layout.html:149
76+
msgid""
77+
"Examples, recipes, and other code in the documentation are additionally "
78+
"licensed under the Zero Clause BSD License."
79+
msgstr""
80+
"Przykłady, przepisy i inny kod w dokumentacji są dodatkowo objęte "
81+
"licencją Zero Clause BSD."
82+
83+
#:python_docs_theme/layout.html:152
84+
#, python-format
85+
msgid""
86+
"See <a href=\"%(license_file)s\">History and License</a> for more "
87+
"information."
88+
msgstr""
89+
"Zobacz <a href=\"%(license_file)s\">Historię i licencję</a> aby uzyskać "
90+
"więcej informacji."
91+
92+
#:python_docs_theme/layout.html:155
93+
#, python-format
94+
msgid"Hosted on %(hosted_on)s."
95+
msgstr"Hostowane na %(hosted_on)s."
96+
97+
#:python_docs_theme/layout.html:163
98+
#, python-format
99+
msgid"Last updated on %(last_updated)s."
100+
msgstr"Ostatnia aktualizacja %(last_updated)s."
101+
102+
#:python_docs_theme/layout.html:166
103+
#, python-format
104+
msgid"<a href=\"%(theme_issues_url)s\">Found a bug</a>?"
105+
msgstr"<a href=\"%(theme_issues_url)s\">Znalazłeś(-aś) błąd</a>?"
106+
107+
#:python_docs_theme/layout.html:170
108+
#, python-format
109+
msgid""
110+
"Created using <a href=\"https://www.sphinx-doc.org/\">Sphinx</a> "
111+
"%(sphinx_version)s."
112+
msgstr""
113+
"Stworzone za pomocą <a href=\"https://www.sphinx-doc.org/\">Sphinx</a> "
114+
"%(sphinx_version)s."
115+
116+
#:python_docs_theme/static/copybutton.js:30
117+
#:python_docs_theme/static/copybutton.js:55
118+
msgid"Copy"
119+
msgstr"Kopiuj"
120+
121+
#:python_docs_theme/static/copybutton.js:31
122+
msgid"Copy to clipboard"
123+
msgstr"Skopiuj do schowka"
124+
125+
#:python_docs_theme/static/copybutton.js:53
126+
msgid"Copied!"
127+
msgstr"Skopiowano!"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp