Skip to content

Commit e087205

Browse files
authored
Update to handle shared content. (#35)
1 parent a43371f commit e087205

File tree

10 files changed

+60
-46
lines changed

10 files changed

+60
-46
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
_build
33
comment.md
44

5+
# uv
6+
uv.lock
7+
58
# Byte-compiled / optimized / DLL files
69
__pycache__/
710
*.py[codz]

docs/locales/de/translations.po

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ msgstr ""
99
"MIME-Version: 1.0\n"
1010
"Content-Type: text/plain; charset=UTF-8\n"
1111
"Content-Transfer-Encoding: 8bit\n"
12-
"X-Generator: Translate Toolkit 3.16.0\n"
12+
"X-Generator: Translate Toolkit 3.16.1\n"
1313

1414
#: docs/en/SUMMARY.md:1
1515
#: docs/en/section_one/index.md:1

docs/locales/fr/translations.po

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ msgstr ""
99
"MIME-Version: 1.0\n"
1010
"Content-Type: text/plain; charset=UTF-8\n"
1111
"Content-Transfer-Encoding: 8bit\n"
12-
"X-Generator: Translate Toolkit 3.16.0\n"
12+
"X-Generator: Translate Toolkit 3.16.1\n"
1313

1414
#: docs/en/SUMMARY.md:1
1515
#: docs/en/section_one/index.md:1

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ dependencies = [
3737
"python-Levenshtein==0.27.1",
3838
"PyYAML==6.0.2",
3939
"polib==1.2.0",
40-
"translate-toolkit @ git+https://github.com/kattni/translate@onefile-timestamp",
40+
"translate-toolkit==3.16.1",
4141
]
4242

4343
[dependency-groups]

src/beeware_docs_tools/build_md_translations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def main():
109109
temp_md_path = Path(temp_md_directory)
110110

111111
# If source code directory or directories provided, symlink to the
112-
# temp directory so it is available relative to the build.
112+
# temp directory, so it is available relative to the build.
113113
if args.source_code:
114114
for source in args.source_code:
115115
# If source includes subdirectories, the parent directory
@@ -131,7 +131,7 @@ def main():
131131

132132
# Load the config.yml file, add the version_number to extra,
133133
# add the base_path to Snippets, and dump the updated copy to
134-
# the temp directory so it is available relative to the build.
134+
# the temp directory, so it is available relative to the build.
135135
with (PROJECT_PATH / "docs/config.yml").open() as f:
136136
config_file = yaml.load(f, Loader=yaml.SafeLoader)
137137

src/beeware_docs_tools/build_po_translations.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
def parse_args() -> Namespace:
2424
parser = ArgumentParser()
2525
parser.add_argument("language_code", nargs="*")
26+
parser.add_argument("-d", "--docs-directory", type=Path, default="docs")
2627
args = parser.parse_args()
2728

2829
for language in args.language_code:
@@ -35,66 +36,67 @@ def parse_args() -> Namespace:
3536

3637

3738
def pot_to_po(
38-
docs_path: Path,
39+
docs: Path,
3940
language: str,
4041
output_path: Path,
4142
) -> None:
4243
"""
4344
Run `pot2po` with the provided directories.
4445
45-
:param docs_path: The directory fragment, relative to the project root,
46-
containing the `locales` directory.
46+
:param root_path: The root directory of the documentation content.
47+
:param docs: The directory fragment, relative to the root path, containing
48+
the `locales` directory.
4749
:param language: The language code to convert.
4850
:param output_path: The root of the output folder where the updated PO file
4951
will be written.
5052
"""
51-
(output_path / docs_path / language).mkdir(parents=True)
53+
(output_path / docs / language).mkdir(parents=True)
5254
subprocess.run(
5355
[
5456
"pot2po",
55-
f"--template={docs_path / f'locales/{language}/translations.po'}",
56-
f"--input={docs_path / 'locales/template/translations.pot'}",
57-
f"--output={output_path / docs_path / language}",
57+
f"--template={Path.cwd() / docs / f'locales/{language}/translations.po'}",
58+
f"--input={Path.cwd() / docs / 'locales/template/translations.pot'}",
59+
f"--output={output_path / docs / language}",
5860
],
5961
check=True,
6062
)
6163

6264

63-
def generate_po_files(docs_path: Path) -> None:
65+
def generate_po_files(docs: Path) -> None:
6466
"""
6567
Generate PO files from PO template (POT) files.
6668
67-
:param docs_path: The directory fragment, relative to the project root,
68-
containing the `locales` directory.
69+
:param root_path: The root directory of the documentation content.
70+
:param docs: The directory fragment, relative to the root path, containing
71+
the `locales` translation files directories.
6972
"""
7073
args = parse_args()
7174

7275
with TemporaryDirectory() as temp_dir:
7376
temp_path = Path(temp_dir)
7477

7578
for language in args.language_code:
76-
print(f"Processing {language} content from {docs_path}")
79+
print(f"Processing {language} content from {docs}")
7780

7881
# Generates PO files from POT files into a temporary destination
7982
# directory.
8083
pot_to_po(
81-
docs_path=docs_path,
84+
docs=docs,
8285
language=language,
8386
output_path=temp_path,
8487
)
8588

8689
# Copies the updated PO file to the `docs` directory.
8790
shutil.copyfile(
88-
(temp_dir / docs_path / language / "translations.po"),
89-
(docs_path / f"locales/{language}/translations.po"),
91+
(temp_path / docs / language / "translations.po"),
92+
(Path.cwd() / docs / f"locales/{language}/translations.po"),
9093
)
9194

9295

9396
def main():
94-
# Generate primary content PO files
95-
generate_po_files(Path("docs"))
96-
# Generate shared content PO files
97-
generate_po_files(Path("src/beeware_docs_tools/shared_content"))
97+
args = parse_args()
98+
# Generate PO files
99+
generate_po_files(args.docs_directory)
98100

99101

100102
if __name__ == "__main__":

src/beeware_docs_tools/build_pot_translations.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import subprocess
2+
from argparse import ArgumentParser, Namespace
23
from pathlib import Path
34
from tempfile import TemporaryDirectory
45

@@ -18,7 +19,15 @@
1819
# translated site in a given language.
1920

2021

21-
def markdown_to_pot(docs_path: Path, working_path: Path) -> None:
22+
def parse_args() -> Namespace:
23+
parser = ArgumentParser()
24+
parser.add_argument("-d", "--docs-directory", type=Path, default="docs")
25+
args = parser.parse_args()
26+
27+
return args
28+
29+
30+
def markdown_to_pot(docs: Path, working_path: Path) -> None:
2231
"""
2332
Run `md2po` with provided input and output directories, with `--pot` flag to
2433
generate PO template (POT) files.
@@ -30,21 +39,20 @@ def markdown_to_pot(docs_path: Path, working_path: Path) -> None:
3039
* `--timestamp` ensures that new files are only generated when there is new
3140
content.
3241
33-
:param docs_path: A directory fragment, relative to the project root,
34-
containing the `en` Markdown content and `locales` translation files
35-
directories.
42+
:param docs: The directory fragment, relative to the root path, containing
43+
the `en` Markdown content and `locales` translation files directories.
3644
:param working_path: The directory considered `/` for the input file call.
3745
This ensures that the location strings are accurate in the POT and PO
3846
files.
3947
"""
4048
# Ensure the output directory exists
41-
output_path = Path.cwd() / docs_path / "locales/template"
49+
output_path = Path.cwd() / docs / "locales/template"
4250
output_path.mkdir(parents=True, exist_ok=True)
4351

4452
subprocess.run(
4553
[
4654
"md2po",
47-
f"--input={docs_path / 'en'}",
55+
f"--input={docs / 'en'}",
4856
f"--output={output_path / 'translations.pot'}",
4957
"--pot",
5058
"--timestamp",
@@ -56,40 +64,39 @@ def markdown_to_pot(docs_path: Path, working_path: Path) -> None:
5664
)
5765

5866

59-
def generate_pot_files(docs_path: Path) -> None:
67+
def generate_pot_files(docs: Path) -> None:
6068
"""
6169
Generate the PO template (POT) files for the content in the provided
6270
directory.
6371
64-
:param docs_path: A directory fragment, relative to the project root,
65-
containing the `en` Markdown content and `locales` translation files
66-
directories. This will become the msg* string location prefix in the
67-
generated POT files.
72+
:param docs: The directory fragment, relative to the root path, containing
73+
the `en` Markdown content and `locales` translation files directories.
74+
This will become the msg* string location prefix in the generated POT
75+
files.
6876
"""
6977
with TemporaryDirectory() as temp_working_directory:
7078
temp_working_path = Path(temp_working_directory)
7179

72-
(temp_working_path / docs_path).parent.mkdir(parents=True, exist_ok=True)
80+
(temp_working_path / docs).parent.mkdir(parents=True, exist_ok=True)
7381

7482
try:
75-
(temp_working_path / docs_path).symlink_to(
76-
Path.cwd() / docs_path,
83+
(temp_working_path / docs).symlink_to(
84+
Path.cwd() / docs,
7785
target_is_directory=True,
7886
)
7987
except FileExistsError:
8088
pass
8189

8290
markdown_to_pot(
83-
docs_path=docs_path,
91+
docs=docs,
8492
working_path=temp_working_path,
8593
)
8694

8795

8896
def main():
89-
# Generate primary content POT files.
90-
generate_pot_files(Path("docs"))
91-
# # Generate shared content POT files.
92-
generate_pot_files(Path("src/beeware_docs_tools/shared_content"))
97+
args = parse_args()
98+
# Generate POT files.
99+
generate_pot_files(args.docs_directory)
93100

94101

95102
if __name__ == "__main__":

src/beeware_docs_tools/shared_content/locales/de/translations.po

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ msgid ""
22
msgstr ""
33
"Project-Id-Version: PACKAGE VERSION\n"
44
"Report-Msgid-Bugs-To: \n"
5-
"POT-Creation-Date: 2025-09-04 00:03-0400\n"
5+
"POT-Creation-Date: 2025-09-13 15:51-0500\n"
66
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
77
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
88
"Language-Team: LANGUAGE <[email protected]>\n"
99
"MIME-Version: 1.0\n"
1010
"Content-Type: text/plain; charset=UTF-8\n"
1111
"Content-Transfer-Encoding: 8bit\n"
12-
"X-Generator: Translate Toolkit 3.16.0\n"
12+
"X-Generator: Translate Toolkit 3.16.1\n"
1313

1414
#: src/beeware_docs_tools/shared_content/en/style_guide.md:1
1515
#, fuzzy

src/beeware_docs_tools/shared_content/locales/fr/translations.po

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ msgid ""
22
msgstr ""
33
"Project-Id-Version: PACKAGE VERSION\n"
44
"Report-Msgid-Bugs-To: \n"
5-
"POT-Creation-Date: 2025-09-04 00:03-0400\n"
5+
"POT-Creation-Date: 2025-09-13 15:51-0500\n"
66
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
77
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
88
"Language-Team: LANGUAGE <[email protected]>\n"
99
"MIME-Version: 1.0\n"
1010
"Content-Type: text/plain; charset=UTF-8\n"
1111
"Content-Transfer-Encoding: 8bit\n"
12-
"X-Generator: Translate Toolkit 3.16.0\n"
12+
"X-Generator: Translate Toolkit 3.16.1\n"
1313

1414
#: src/beeware_docs_tools/shared_content/en/style_guide.md:1
1515
#, fuzzy

tox.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ deps =
1717
commands:
1818
!lint-!all-!translate-!machine-!live-!en-!de-!fr : build_md_translations {posargs} --source-code=src en
1919
translate : build_pot_translations
20+
translate : build_pot_translations -d src/beeware_docs_tools/shared_content
2021
translate : build_po_translations de fr
22+
translate : build_po_translations de fr -d src/beeware_docs_tools/shared_content
2123
translate : update_machine_translations --soft-fail --docs {[docs]docs_dir} --docs {[docs]shared_content_dir} de fr
2224
lint : markdown-checker --dir {[docs]docs_dir} --func check_broken_urls
2325
lint : pyspelling

0 commit comments

Comments
 (0)