mirror of
https://github.com/thetasoft/wulkplot-translations.git
synced 2026-03-28 16:14:48 +00:00
Meta: Move tools to Wulkplot repo
This commit is contained in:
@@ -1,35 +0,0 @@
|
|||||||
import subprocess
|
|
||||||
import glob
|
|
||||||
import os
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
TRANSLATIONS_DIR = Path(__file__).resolve().parent.parent
|
|
||||||
VENV_RUNNER_DIR = TRANSLATIONS_DIR / "tools" / "venv.py"
|
|
||||||
|
|
||||||
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 = ["python", str(VENV_RUNNER_DIR), "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)
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
import sys
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from PyQt6.QtCore import QProcess
|
|
||||||
from PyQt6.QtWidgets import (
|
|
||||||
QApplication,
|
|
||||||
QComboBox,
|
|
||||||
QDialog,
|
|
||||||
QDialogButtonBox,
|
|
||||||
QFormLayout,
|
|
||||||
QLabel,
|
|
||||||
QMessageBox,
|
|
||||||
)
|
|
||||||
|
|
||||||
TRANSLATIONS_DIR = Path(__file__).resolve().parent.parent
|
|
||||||
VENV_RUNNER = TRANSLATIONS_DIR / "tools" / "venv.py"
|
|
||||||
|
|
||||||
class TranslateDialog(QDialog):
|
|
||||||
def __init__(self, parent=None):
|
|
||||||
super().__init__(parent)
|
|
||||||
self.setWindowTitle("Choose Translation File")
|
|
||||||
|
|
||||||
ts_files = sorted([f.name for f in TRANSLATIONS_DIR.glob("*.ts")])
|
|
||||||
if not ts_files:
|
|
||||||
QMessageBox.information(
|
|
||||||
self,
|
|
||||||
"No Files",
|
|
||||||
f"No .ts files found in {TRANSLATIONS_DIR}",
|
|
||||||
)
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
self.combo = QComboBox()
|
|
||||||
self.combo.addItems(ts_files)
|
|
||||||
|
|
||||||
layout = QFormLayout()
|
|
||||||
layout.addRow(QLabel("Select a .ts file:"), self.combo)
|
|
||||||
|
|
||||||
buttons = QDialogButtonBox(
|
|
||||||
QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel
|
|
||||||
)
|
|
||||||
buttons.accepted.connect(self.run_translation)
|
|
||||||
buttons.rejected.connect(self.reject)
|
|
||||||
layout.addWidget(buttons)
|
|
||||||
|
|
||||||
self.setLayout(layout)
|
|
||||||
|
|
||||||
def run_translation(self):
|
|
||||||
selected = self.combo.currentText()
|
|
||||||
ts_path = TRANSLATIONS_DIR / selected
|
|
||||||
|
|
||||||
success = QProcess.startDetached(
|
|
||||||
sys.executable,
|
|
||||||
[str(VENV_RUNNER), "linguist", str(ts_path)]
|
|
||||||
)
|
|
||||||
if not success:
|
|
||||||
QMessageBox.critical(
|
|
||||||
self,
|
|
||||||
"Error",
|
|
||||||
"Failed to launch translation process.",
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
self.accept()
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
app = QApplication(sys.argv)
|
|
||||||
dialog = TranslateDialog()
|
|
||||||
dialog.exec()
|
|
||||||
sys.exit(0)
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
import subprocess
|
|
||||||
import glob
|
|
||||||
import os
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent.parent
|
|
||||||
TRANSLATIONS_DIR = BASE_DIR / "translations"
|
|
||||||
VENV_RUNNER_DIR = TRANSLATIONS_DIR / "tools" / "venv.py"
|
|
||||||
|
|
||||||
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 = ["python", str(VENV_RUNNER_DIR), "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.")
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
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.")
|
|
||||||
if sys.argv[1] == "pylupdate6":
|
|
||||||
subprocess.run(sys.argv[1:], check=True)
|
|
||||||
else:
|
|
||||||
subprocess.run(["qt6-tools"] + sys.argv[1:], check=True)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
if len(sys.argv) < 2:
|
|
||||||
print("Usage: python venv.py [pylupdate6|lrelease|linguist] <args>")
|
|
||||||
sys.exit(1)
|
|
||||||
main()
|
|
||||||
Reference in New Issue
Block a user