-
-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathcompile_translations.py
55 lines (45 loc) · 1.49 KB
/
compile_translations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""Compile language files from ./locale"""
import logging
import subprocess
from pathlib import Path
from src.tauon.t_modules.logging import CustomLoggingFormatter
# DEBUG+ to file and std_err
logging.basicConfig(
level=logging.DEBUG,
handlers=[
logging.StreamHandler(),
# logging.FileHandler('/tmp/tauon.log'),
],
)
# INFO+ to std_err
logging.getLogger().handlers[0].setLevel(logging.INFO)
logging.getLogger().handlers[0].setFormatter(CustomLoggingFormatter())
def main() -> None:
compile_failure = False
script_dir = Path(__file__).parent
locale_folder = script_dir / "locale"
languages = locale_folder.iterdir()
for lang_file in languages:
if lang_file.name in ("messages.pot", ".DS_Store"):
continue
po_path = locale_folder / lang_file.name / "LC_MESSAGES" / "tauon.po"
# mo_path = locale_folder / lang_file.name / "LC_MESSAGES" / "tauon.mo"
mo_dirpath = script_dir / "src" / "tauon" / "locale" / lang_file.name / "LC_MESSAGES"
mo_path = mo_dirpath / "tauon.mo"
if not mo_path.exists():
(mo_dirpath).mkdir(parents=True)
if po_path.exists():
try:
subprocess.run(["msgfmt", "-o", mo_path, po_path], check=True)
except Exception:
logging.exception(f"Failed to compile translations for {lang_file.name}")
compile_failure = True
else:
logging.info(f"Compiled: {lang_file.name}")
else:
logging.critical(f"Missing po file: {po_path}")
if compile_failure:
raise Exception("Compiling had errors!")
logging.info("Done")
if __name__ == "__main__":
main()