-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
update_translations.py
50 lines (36 loc) · 1.25 KB
/
update_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
"""Update language files from ./locale"""
import os
import subprocess
import sys
from pathlib import Path
def main() -> None:
if not Path("pygettext.py").is_file():
print("ERROR: Please add a copy of pygettext.py to this dir from the Python Tools dir")
sys.exit()
locale_folder = "locale"
pot_path = Path(locale_folder) / "messages.pot"
print("Generate template")
root_dir = "src"
# Collect all .py file paths
py_files = []
for dirpath, _, filenames in os.walk(root_dir):
py_files.extend(os.path.join(dirpath, file) for file in filenames if file.endswith(".py"))
# Run pygettext.py with all .py files as arguments
if py_files:
subprocess.run(["python", "pygettext.py", *py_files], check=True)
print("Copy template")
subprocess.run(["cp", "messages.pot", pot_path], check=True)
subprocess.run(["rm", "messages.pot"], check=True)
languages = os.listdir(locale_folder)
for lang_file in languages:
if lang_file == "messages.pot":
continue
po_path = Path(locale_folder) / lang_file / "LC_MESSAGES" / "tauon.po"
if Path(po_path).exists():
subprocess.run(["msgmerge", "-U", po_path, pot_path], check=True)
print(f"Updated: {lang_file}")
else:
print(f"Missing po file: {po_path}")
print("Done")
if __name__ == "__main__":
main()