|
1 |
| -#!/usr/bin/env python3 |
2 | 1 | """Script for handling translations with Babel"""
|
| 2 | + |
3 | 3 | from __future__ import annotations
|
4 | 4 |
|
5 | 5 | import argparse
|
|
8 | 8 | import tomllib
|
9 | 9 | from pathlib import Path
|
10 | 10 |
|
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 |
| - |
15 | 11 | # Global variables used by pybabel below (paths relative to PROJECT_DIR)
|
16 |
| -DOMAIN = "messages" |
| 12 | +DOMAIN = "python-docs-theme" |
17 | 13 | COPYRIGHT_HOLDER = "Python Software Foundation"
|
18 | 14 | SOURCE_DIR = "python_docs_theme"
|
19 |
| -LOCALES_DIR = f"{SOURCE_DIR}/locales" |
20 |
| -POT_FILE = Path(LOCALES_DIR, f"{DOMAIN}.pot") |
21 | 15 | MAPPING_FILE = ".babel.cfg"
|
22 | 16 |
|
| 17 | +PROJECT_DIR = Path(__file__).resolve().parent |
| 18 | +PYPROJECT_TOML = PROJECT_DIR / "pyproject.toml" |
| 19 | +INIT_PY = PROJECT_DIR / SOURCE_DIR / "__init__.py" |
| 20 | +LOCALES_DIR = f"{SOURCE_DIR}/locale" |
| 21 | +POT_FILE = Path(LOCALES_DIR, f"{DOMAIN}.pot") |
| 22 | + |
23 | 23 |
|
24 | 24 | def get_project_info() -> dict:
|
25 | 25 | """Retrieve project's info to populate the message catalog template"""
|
@@ -75,21 +75,32 @@ def init_locale(locale: str) -> None:
|
75 | 75 | if pofile.exists():
|
76 | 76 | print(f"There is already a message catalog for locale {locale}, skipping.")
|
77 | 77 | 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 | + ] |
79 | 90 | subprocess.run(cmd, cwd=PROJECT_DIR, check=True)
|
80 | 91 |
|
81 | 92 |
|
82 | 93 | def update_catalogs(locale: str) -> None:
|
83 | 94 | """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] |
85 | 96 | if locale:
|
86 | 97 | cmd.extend(["-l", locale])
|
87 | 98 | subprocess.run(cmd, cwd=PROJECT_DIR, check=True)
|
88 | 99 |
|
89 | 100 |
|
90 | 101 | def compile_catalogs(locale: str) -> None:
|
91 | 102 | """Compile existing message catalogs"""
|
92 |
| - cmd = ["pybabel", "compile", "-d", LOCALES_DIR] |
| 103 | + cmd = ["pybabel", "compile", "-d", LOCALES_DIR, "-D", DOMAIN] |
93 | 104 | if locale:
|
94 | 105 | cmd.extend(["-l", locale])
|
95 | 106 | subprocess.run(cmd, cwd=PROJECT_DIR, check=True)
|
|
0 commit comments