mirror of
https://github.com/thetasoft/wulkplot-translations.git
synced 2026-03-28 16:14:48 +00:00
Feat: Add simple translation launcher dialog
This commit is contained in:
@@ -4,7 +4,7 @@ import os
|
||||
from pathlib import Path
|
||||
|
||||
TRANSLATIONS_DIR = Path(__file__).resolve().parent.parent
|
||||
VENV_RUNNER_DIR = TRANSLATIONS_DIR / "tools" / "translation_venv.py"
|
||||
VENV_RUNNER_DIR = TRANSLATIONS_DIR / "tools" / "venv.py"
|
||||
|
||||
ts_files = glob.glob(str(TRANSLATIONS_DIR / "*.ts"))
|
||||
success = []
|
||||
|
||||
69
tools/translate.py
Normal file
69
tools/translate.py
Normal file
@@ -0,0 +1,69 @@
|
||||
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)
|
||||
@@ -5,7 +5,7 @@ from pathlib import Path
|
||||
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent.parent
|
||||
TRANSLATIONS_DIR = BASE_DIR / "translations"
|
||||
VENV_RUNNER_DIR = TRANSLATIONS_DIR / "tools" / "translation_venv.py"
|
||||
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
|
||||
|
||||
@@ -39,6 +39,6 @@ def main():
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python translation_venv.py [pylupdate6|lrelease|linguist] <args>")
|
||||
print("Usage: python venv.py [pylupdate6|lrelease|linguist] <args>")
|
||||
sys.exit(1)
|
||||
main()
|
||||
Reference in New Issue
Block a user