Repository navigation
Expand file tree
/
Copy pathcompile_translations.py
More file actions
executable file
·66 lines (56 loc) · 2.01 KB
/
Copy pathcompile_translations.py
File metadata and controls
executable file
·66 lines (56 loc) · 2.01 KB
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
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
"""
Compile Qt translation files (.ts) to binary format (.qm)
Uses lrelease to compile translations
"""
import sys
import subprocess
import shutil
from pathlib import Path
def find_lrelease():
"""Find lrelease command"""
for cmd in ['lrelease-qt6', 'lrelease']:
if shutil.which(cmd):
return cmd
return None
def compile_translations():
"""Compile .ts files to .qm"""
lrelease = find_lrelease()
if not lrelease:
print("[ERROR] lrelease not found")
print("")
print("To compile translations, you need Qt's lrelease tool:")
print(" Ubuntu/Debian: sudo apt install qttools5-dev-tools")
print(" Fedora: sudo dnf install qt6-qttools")
print(" Arch: sudo pacman -S qt6-tools")
print("")
print("After installation, run this script again.")
sys.exit(1)
i18n_dir = Path(__file__).parent / 'i18n'
ts_files = list(i18n_dir.glob('*.ts'))
if not ts_files:
print("[WARNING] No .ts files found in i18n/")
sys.exit(0)
print(f"[*] Compiling translations with {lrelease}...")
for ts_file in ts_files:
qm_file = ts_file.with_suffix('.qm')
try:
result = subprocess.run([lrelease, str(ts_file), '-qm', str(qm_file)],
capture_output=True,
text=True)
if result.returncode == 0:
print(f"[OK] Compiled {ts_file.name} -> {qm_file.name}")
else:
print(f"[ERROR] Failed to compile {ts_file.name}")
if result.stderr:
print(result.stderr)
except Exception as e:
print(f"[ERROR] Error compiling {ts_file.name}: {e}")
print("[OK] Translation compilation completed")
if __name__ == '__main__':
try:
from PyQt6.QtCore import QTranslator
compile_translations()
except ImportError:
print("[ERROR] PyQt6 not installed")
sys.exit(1)