prepare i18n

This commit is contained in:
2021-10-26 09:15:49 +02:00
parent 16abe95dac
commit aea1e49fe8
3 changed files with 49 additions and 5 deletions

16
main.py
View File

@@ -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()

29
messages_de.ts Normal file
View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>MainWindow</name>
<message>
<location filename="main.py" line="22" />
<source>RavenLog</source>
<translation>RavenLog</translation>
</message>
<message>
<location filename="main.py" line="36" />
<source>Font Size:</source>
<translation>Schriftgröße:</translation>
</message>
<message>
<location filename="main.py" line="72" />
<source>File</source>
<comment>name of the file menu</comment>
<translation>Datei</translation>
</message>
<message>
<location filename="main.py" line="73" />
<source>Close</source>
<comment>menu item to close the application</comment>
<translation>Schließen</translation>
</message>
</context>
</TS>

9
pylupdate.py Normal file
View File

@@ -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"])