aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside-tools
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2024-02-09 13:07:34 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2024-02-12 13:15:46 +0100
commit34c4dab7cf68450959383240a68433b979aba821 (patch)
treecc55319626e847e40ce627d0be96e0dc0d6a0a29 /sources/pyside-tools
parent6b5622f44b32c6808f4de2456744f81391c24235 (diff)
pyside6-project: Add a command for running lupdate
[ChangeLog][PySide6] pyside6-project now has an lupdate mode updating translation files (.ts) from the sources. Change-Id: I853e55455fff2c0c22a7099c650e4bd3b2fc52c4 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'sources/pyside-tools')
-rw-r--r--sources/pyside-tools/project.py24
-rw-r--r--sources/pyside-tools/project/project_data.py14
2 files changed, 34 insertions, 4 deletions
diff --git a/sources/pyside-tools/project.py b/sources/pyside-tools/project.py
index ff6a4c5d5..b3d8b9cd6 100644
--- a/sources/pyside-tools/project.py
+++ b/sources/pyside-tools/project.py
@@ -37,6 +37,7 @@ run Builds the project and runs the first file")
clean Cleans the build artifacts")
qmllint Runs the qmllint tool
deploy Deploys the application
+lupdate Updates translation (.ts) files
new-ui Creates a new QtWidgets project with a Qt Designer-based main window
new-widget Creates a new QtWidgets project with a main window
new-quick Creates a new QtQuick project
@@ -45,6 +46,7 @@ new-quick Creates a new QtQuick project
UIC_CMD = "pyside6-uic"
RCC_CMD = "pyside6-rcc"
LRELEASE_CMD = "pyside6-lrelease"
+LUPDATE_CMD = "pyside6-lupdate"
QMLTYPEREGISTRAR_CMD = "pyside6-qmltyperegistrar"
QMLLINT_CMD = "pyside6-qmllint"
DEPLOY_CMD = "pyside6-deploy"
@@ -224,6 +226,24 @@ class Project:
cmd.extend([str(self.project.main_file), "-f"])
run_command(cmd, cwd=self.project.project_file.parent)
+ def lupdate(self):
+ for sub_project_file in self.project.sub_projects_files:
+ Project(project_file=sub_project_file).lupdate()
+
+ if not self.project.ts_files:
+ print(f"{self.project.project_file.name}: No .ts file found.",
+ file=sys.stderr)
+ return
+
+ source_files = self.project.python_files + self.project.ui_files
+ cmd_prefix = [LUPDATE_CMD] + [p.name for p in source_files]
+ cmd_prefix.append("-ts")
+ for ts_file in self.project.ts_files:
+ if requires_rebuild(source_files, ts_file):
+ cmd = cmd_prefix
+ cmd.append(ts_file.name)
+ run_command(cmd, cwd=self.project.project_file.parent)
+
if __name__ == "__main__":
parser = ArgumentParser(description=__doc__, formatter_class=RawTextHelpFormatter)
@@ -232,7 +252,7 @@ if __name__ == "__main__":
parser.add_argument("--force", "-f", action="store_true", help="Force rebuild")
parser.add_argument("--qml-module", "-Q", action="store_true",
help="Perform check for QML module")
- mode_choices = ["build", "run", "clean", "qmllint", "deploy"]
+ mode_choices = ["build", "run", "clean", "qmllint", "deploy", "lupdate"]
mode_choices.extend(NEW_PROJECT_TYPES.keys())
parser.add_argument("mode", choices=mode_choices, default="build",
type=str, help=MODE_HELP)
@@ -267,6 +287,8 @@ if __name__ == "__main__":
project.qmllint()
elif mode == "deploy":
project.deploy()
+ elif mode == "lupdate":
+ project.lupdate()
else:
print(f"Invalid mode {mode}", file=sys.stderr)
sys.exit(1)
diff --git a/sources/pyside-tools/project/project_data.py b/sources/pyside-tools/project/project_data.py
index 416089dce..52e20be3f 100644
--- a/sources/pyside-tools/project/project_data.py
+++ b/sources/pyside-tools/project/project_data.py
@@ -7,9 +7,9 @@ import subprocess
import sys
from typing import List, Tuple
from pathlib import Path
-from . import (METATYPES_JSON_SUFFIX, PROJECT_FILE_SUFFIX, qt_metatype_json_dir,
- MOD_CMD, QML_IMPORT_MAJOR_VERSION, QML_IMPORT_MINOR_VERSION, QML_IMPORT_NAME,
- QT_MODULES)
+from . import (METATYPES_JSON_SUFFIX, PROJECT_FILE_SUFFIX, TRANSLATION_SUFFIX,
+ qt_metatype_json_dir, MOD_CMD, QML_IMPORT_MAJOR_VERSION,
+ QML_IMPORT_MINOR_VERSION, QML_IMPORT_NAME, QT_MODULES)
def is_python_file(file: Path) -> bool:
@@ -34,6 +34,8 @@ class ProjectData:
self._ui_files: List[Path] = []
# qrc files
self._qrc_files: List[Path] = []
+ # ts files
+ self._ts_files: List[Path] = []
with project_file.open("r") as pyf:
pyproject = json.load(pyf)
@@ -53,6 +55,8 @@ class ProjectData:
self._ui_files.append(file)
elif file.suffix == ".qrc":
self._qrc_files.append(file)
+ elif file.suffix == TRANSLATION_SUFFIX:
+ self._ts_files.append(file)
if not self.main_file:
self._find_main_file()
@@ -90,6 +94,10 @@ class ProjectData:
return self._qml_files
@property
+ def ts_files(self):
+ return self._ts_files
+
+ @property
def sub_projects_files(self):
return self._sub_projects_files