diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-07-06 11:50:36 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-07-07 13:36:06 +0000 |
commit | d6bc6581b0caf0bab479df10e6b3f9ad9afa952a (patch) | |
tree | 7161f6e73ffdf0e5b6b0ce27791a1923d4417a2d /tests | |
parent | 4049cc198c159e9b50d08d5473739f3082866347 (diff) |
lupdate: Support Python
Port over the parser from pyside2-lupdate, remove the encoding and
clean it up with clang-tidy. Add a test.
[ChangeLog][lupdate] lupdate now supports Python.
Task-number: PYSIDE-1252
Change-Id: Id64e7a4be90e66aad154d0546e48cf1a88e5cb3a
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
(cherry picked from commit 7bd1a834e048f2ecb68411e43d2a2681604955a5)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
3 files changed, 95 insertions, 0 deletions
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsepython/main.py b/tests/auto/linguist/lupdate/testdata/good/parsepython/main.py new file mode 100644 index 000000000..0e6b60c5b --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/good/parsepython/main.py @@ -0,0 +1,53 @@ +from pathlib import Path +import sys + +from PySide6.QtCore import (QItemSelection, QLibraryInfo, QLocale, QTranslator, + Qt, Slot) +from PySide6.QtWidgets import (QAbstractItemView, QApplication, QListWidget, + QMainWindow, QWidget) + + +import linguist_rc + + +class Window(QMainWindow): + def __init__(self): + super().__init__() + file_menu = self.menuBar().addMenu(self.tr("&File")) + quit_action = file_menu.addAction(self.tr("Quit")) + quit_action.setShortcut(self.tr("CTRL+Q")) + quit_action.triggered.connect(self.close) + help_menu = self.menuBar().addMenu(self.tr("&Help")) + about_qt_action = help_menu.addAction(self.tr("About Qt")) + about_qt_action.triggered.connect(qApp.aboutQt) + + self._list_widget = QListWidget() + self._list_widget.setSelectionMode(QAbstractItemView.MultiSelection) + self._list_widget.selectionModel().selectionChanged.connect(self.selection_changed) + self._list_widget.addItem("C++") + self._list_widget.addItem("Java") + self._list_widget.addItem("Python") + self.setCentralWidget(self._list_widget) + + @Slot(QItemSelection, QItemSelection) + def selection_changed(self, selected, deselected): + count = len(self._list_widget.selectionModel().selectedRows()) + message = self.tr("%n language(s) selected", "", count) + self.statusBar().showMessage(message) + + +if __name__ == '__main__': + app = QApplication(sys.argv) + + path = QLibraryInfo.location(QLibraryInfo.TranslationsPath) + translator = QTranslator(app) + if translator.load(QLocale.system(), 'qtbase_', '', path): + app.installTranslator(translator) + translator = QTranslator(app) + path = ':/translations' + if translator.load(QLocale.system(), 'example_', '', path): + app.installTranslator(translator) + + window = Window() + window.show() + sys.exit(app.exec()) diff --git a/tests/auto/linguist/lupdate/testdata/good/parsepython/project.pro b/tests/auto/linguist/lupdate/testdata/good/parsepython/project.pro new file mode 100644 index 000000000..ed8aba541 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/good/parsepython/project.pro @@ -0,0 +1,3 @@ +SOURCES += main.py + +TRANSLATIONS = project.ts diff --git a/tests/auto/linguist/lupdate/testdata/good/parsepython/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/parsepython/project.ts.result new file mode 100644 index 000000000..ef3ecaeca --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/good/parsepython/project.ts.result @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.1"> +<context> + <name>Window</name> + <message> + <location filename="main.py" line="16"/> + <source>&File</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="main.py" line="17"/> + <source>Quit</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="main.py" line="18"/> + <source>CTRL+Q</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="main.py" line="20"/> + <source>&Help</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="main.py" line="21"/> + <source>About Qt</source> + <translation type="unfinished"></translation> + </message> + <message numerus="yes"> + <location filename="main.py" line="35"/> + <source>%n language(s) selected</source> + <translation type="unfinished"> + <numerusform></numerusform> + </translation> + </message> +</context> +</TS> |