From aea1e49fe8f7467588c2794f4c8c727574248575 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Tue, 26 Oct 2021 09:15:49 +0200 Subject: [PATCH] prepare i18n --- main.py | 16 +++++++++++----- messages_de.ts | 29 +++++++++++++++++++++++++++++ pylupdate.py | 9 +++++++++ 3 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 messages_de.ts create mode 100644 pylupdate.py diff --git a/main.py b/main.py index 9af58ad..5eec7b2 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,8 @@ +import os import re +from PyQt6 import QtCore +from PyQt6.lupdate import lupdate from PyQt6.QtWidgets import * from PyQt6.QtCore import * from PyQt6.QtGui import * @@ -15,9 +18,8 @@ MAX_LINE_LENGTH = 4096 class MainWindow(QMainWindow): def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) - self.settings = Settings() - self.setWindowTitle("RavenLog") + self.setWindowTitle(self.tr("RavenLog")) self.setGeometry(0, 0, 640, 480) self.setDockNestingEnabled(True) @@ -31,7 +33,7 @@ class MainWindow(QMainWindow): def create_main_tool_bar(self): result = QToolBar("main toolbar") - result.addWidget(QLabel("Font Size:")) + result.addWidget(QLabel(self.tr("Font Size:"))) font_size = QComboBox(result) for s in range(3,30): font_size.addItem(str(s)) @@ -67,8 +69,8 @@ class MainWindow(QMainWindow): def create_menu_bar(self) -> QMenuBar: menu_bar = QMenuBar() - file_menu = QMenu("File", self) - close_action = QAction("Close", self) + file_menu = QMenu(self.tr("File", "name of the file menu"), self) + close_action = QAction(self.tr("Close", "menu item to close the application"), self) close_action.triggered.connect(self.close) file_menu.addAction(close_action) @@ -84,6 +86,10 @@ class MainWindow(QMainWindow): if __name__ == "__main__": app = QApplication(sys.argv) + #translator = QTranslator() + #if translator.load(QLocale("de"), "messages_de.ts"): + # app.installTranslator(translator) + window = MainWindow() window.show() diff --git a/messages_de.ts b/messages_de.ts new file mode 100644 index 0000000..06cd4fd --- /dev/null +++ b/messages_de.ts @@ -0,0 +1,29 @@ + + + + + MainWindow + + + RavenLog + RavenLog + + + + Font Size: + Schriftgröße: + + + + File + name of the file menu + Datei + + + + Close + menu item to close the application + Schließen + + + diff --git a/pylupdate.py b/pylupdate.py new file mode 100644 index 0000000..ffe8b6b --- /dev/null +++ b/pylupdate.py @@ -0,0 +1,9 @@ +import glob +import os + +from PyQt6.lupdate import lupdate + +if __name__ == "__main__": + python_files = glob.glob(r"*.py") + print(python_files) + lupdate(python_files, ["messages_de.ts"]) \ No newline at end of file