From 807aac32378ce52b3eaae88116b236727d220f97 Mon Sep 17 00:00:00 2001 From: Faraphel Date: Sun, 24 Dec 2023 10:46:30 +0100 Subject: [PATCH] added translation support for the UI --- assets/language/french.qm | Bin 0 -> 215 bytes assets/language/french.ts | 22 ++++++++++++++++++++++ main.py | 11 +++++++++++ source/widget/FrameSurvey.py | 7 +++---- source/widget/MyMainWindow.py | 2 +- 5 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 assets/language/french.qm create mode 100644 assets/language/french.ts diff --git a/assets/language/french.qm b/assets/language/french.qm new file mode 100644 index 0000000000000000000000000000000000000000..e007924bd0f1b7dbb223c367feb6e1eedfd3c82e GIT binary patch literal 215 zcmcE7ks@*G{hX<16=n7(EZlo{IRgU&bG%!S6Ofi*VAZ+;q^%iP>mLB=T-G$rIv~xE z3B+@mfrJQyBSR8HB10ZS3PV1S%wtGpDB=JqVFO}zM<+)=7k@u?Ae-B*C^0uRxU{G& uwUQB}m5(8qp%iFR8CZJ>Toa3*YeWcE9Xt#HK()m{h-?W + + + + FrameSurvey + + + ABANDON + Abandonner + + + + SKIP + Passer + + + + NEXT + Suivant + + + diff --git a/main.py b/main.py index 3c1aa2e..919afe0 100644 --- a/main.py +++ b/main.py @@ -1,13 +1,24 @@ import sys + +from PyQt6.QtCore import QTranslator from PyQt6.QtWidgets import QApplication +from source import assets_path from source.widget import MyMainWindow if __name__ == "__main__": + # create the application application = QApplication(sys.argv) + # load the translator to support multiple languages + translator = QTranslator() + application.installTranslator(translator) + translator.load(str(assets_path / "language/french.qm")) + + # create the window window = MyMainWindow() window.show() + # start the application application.exec() diff --git a/source/widget/FrameSurvey.py b/source/widget/FrameSurvey.py index dcd8af1..c6badfd 100644 --- a/source/widget/FrameSurvey.py +++ b/source/widget/FrameSurvey.py @@ -20,7 +20,6 @@ class FrameSurvey(QFrame): signal_success = pyqtSignal() def __init__(self, survey_path: Path | str): - # TODO: translation support super().__init__() # signals @@ -52,18 +51,18 @@ class FrameSurvey(QFrame): self.button_abandon = QPushButton() self._layout_navigation.addWidget(self.button_abandon) - self.button_abandon.setText("Abandonner") + self.button_abandon.setText(self.tr("ABANDON")) self.button_abandon.setStyleSheet("QPushButton { color : red; }") self.button_abandon.clicked.connect(self.quit) # NOQA: connect exist self.button_skip = QPushButton() self._layout_navigation.addWidget(self.button_skip) - self.button_skip.setText("Passer") + self.button_skip.setText(self.tr("SKIP")) self.button_skip.clicked.connect(self.next_survey) # NOQA: connect exist self.button_forward = QPushButton() self._layout_navigation.addWidget(self.button_forward) - self.button_forward.setText("Suivant") + self.button_forward.setText(self.tr("NEXT")) self.button_forward.clicked.connect(self.next_survey) # NOQA: connect exist # progress bar diff --git a/source/widget/MyMainWindow.py b/source/widget/MyMainWindow.py index 47fccc7..b942dc6 100644 --- a/source/widget/MyMainWindow.py +++ b/source/widget/MyMainWindow.py @@ -12,6 +12,6 @@ class MyMainWindow(QMainWindow): super().__init__() self.setWindowIcon(QIcon(str(icon_path.resolve()))) - self.setWindowTitle("Sondage") + self.setWindowTitle(self.tr("SURVEY")) self.setCentralWidget(widget.FrameSurvey("./surveys.json"))