mirror of
https://github.com/thetasoft/wulkplot-translations.git
synced 2026-03-28 16:14:48 +00:00
Feat: Add translation tools
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,5 +3,6 @@
|
|||||||
|
|
||||||
*.qm
|
*.qm
|
||||||
.etag_cache
|
.etag_cache
|
||||||
|
.venv-translations
|
||||||
|
|
||||||
TODO.md
|
TODO.md
|
||||||
35
tools/compile_translations.py
Normal file
35
tools/compile_translations.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import subprocess
|
||||||
|
import glob
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
TRANSLATIONS_DIR = Path(__file__).resolve().parent.parent
|
||||||
|
print(TRANSLATIONS_DIR)
|
||||||
|
|
||||||
|
ts_files = glob.glob(str(TRANSLATIONS_DIR / "*.ts"))
|
||||||
|
success = []
|
||||||
|
failed = []
|
||||||
|
|
||||||
|
print("Compiling .ts files to .qm:")
|
||||||
|
|
||||||
|
for ts_file in ts_files:
|
||||||
|
qm_file = ts_file.replace(".ts", ".qm")
|
||||||
|
cmd = ["qt6-tools", "lrelease", ts_file]
|
||||||
|
result = subprocess.run(cmd, capture_output=True, text=True)
|
||||||
|
|
||||||
|
if result.returncode == 0:
|
||||||
|
print(f"[Compiled]:\t {os.path.basename(ts_file)} → {os.path.basename(qm_file)}")
|
||||||
|
success.append(qm_file)
|
||||||
|
else:
|
||||||
|
print(f"[Failed]:\t {os.path.basename(ts_file)}")
|
||||||
|
print(result.stderr)
|
||||||
|
failed.append(ts_file)
|
||||||
|
|
||||||
|
print("\n--- Summary ---")
|
||||||
|
print(f"{len(success)} succeeded")
|
||||||
|
print(f"{len(failed)} failed")
|
||||||
|
|
||||||
|
if failed:
|
||||||
|
print("\nFailed files:")
|
||||||
|
for f in failed:
|
||||||
|
print(" -", f)
|
||||||
41
tools/translation_venv.py
Normal file
41
tools/translation_venv.py
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import shutil
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
TRANSLATIONS_DIR = Path(__file__).resolve().parent.parent
|
||||||
|
VENV_DIR = TRANSLATIONS_DIR / ".venv-translations"
|
||||||
|
PYTHON_BIN = VENV_DIR / "Scripts" / "python.exe" if os.name == "nt" else VENV_DIR / "bin" / "python"
|
||||||
|
|
||||||
|
def create_venv():
|
||||||
|
print(f"[Setup] Creating virtual environment at {VENV_DIR}...")
|
||||||
|
subprocess.run([sys.executable, "-m", "venv", str(VENV_DIR)], check=True)
|
||||||
|
|
||||||
|
def install_pyqt6_tools():
|
||||||
|
print(f"[Setup] Installing pyqt6-tools in {VENV_DIR}...")
|
||||||
|
subprocess.run([str(PYTHON_BIN), "-m", "pip", "install", "--upgrade", "pip"], check=True)
|
||||||
|
subprocess.run([str(PYTHON_BIN), "-m", "pip", "install", "--pre", "pyqt6-tools"], check=True)
|
||||||
|
|
||||||
|
def run_pyqt6_tools_tool(args):
|
||||||
|
tool = ["qt6-tools"] + args
|
||||||
|
print(f"[Running] {' '.join(tool)}")
|
||||||
|
subprocess.run([str(PYTHON_BIN)] + ["-m"] + tool, check=True)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if not VENV_DIR.exists():
|
||||||
|
create_venv()
|
||||||
|
install_pyqt6_tools()
|
||||||
|
|
||||||
|
if not shutil.which("qt6-tools"):
|
||||||
|
print("[Info] Executing within virtual environment.")
|
||||||
|
run_pyqt6_tools_tool(sys.argv[1:])
|
||||||
|
else:
|
||||||
|
print("Unexpected: qt6-tools found globally, using system environment.")
|
||||||
|
subprocess.run(["qt6-tools"] + sys.argv[1:], check=True)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
print("Usage: python translation_venv.py [pylupdate6|lrelease|linguist] <args>")
|
||||||
|
sys.exit(1)
|
||||||
|
main()
|
||||||
32
tools/update_translations.py
Normal file
32
tools/update_translations.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import subprocess
|
||||||
|
import glob
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
BASE_DIR = Path(__file__).resolve().parent.parent.parent
|
||||||
|
TRANSLATIONS_DIR = BASE_DIR / "translations"
|
||||||
|
|
||||||
|
util_qt_files = glob.glob(str(BASE_DIR / "util_qt" / "**" / "*.py"), recursive=True)
|
||||||
|
source_files = [str(BASE_DIR / "gui.py")] + util_qt_files
|
||||||
|
|
||||||
|
ts_files = [
|
||||||
|
str(TRANSLATIONS_DIR / "wulkplot_de.ts"),
|
||||||
|
str(TRANSLATIONS_DIR / "wulkplot_fr.ts"),
|
||||||
|
str(TRANSLATIONS_DIR / "wulkplot_no.ts"),
|
||||||
|
str(TRANSLATIONS_DIR / "wulkplot_ru.ts"),
|
||||||
|
]
|
||||||
|
|
||||||
|
cmd = ["pylupdate6"] + source_files
|
||||||
|
for ts in ts_files:
|
||||||
|
cmd += ["-ts", ts]
|
||||||
|
|
||||||
|
print("Running command:")
|
||||||
|
print(" ".join(cmd))
|
||||||
|
|
||||||
|
result = subprocess.run(cmd, capture_output=True, text=True)
|
||||||
|
|
||||||
|
if result.returncode != 0:
|
||||||
|
print("Error:")
|
||||||
|
print(result.stderr)
|
||||||
|
else:
|
||||||
|
print("pylupdate6 completed successfully.")
|
||||||
Reference in New Issue
Block a user