i18n with QT
This commit is contained in:
16
main.py
16
main.py
@@ -1,10 +1,11 @@
|
||||
import logging
|
||||
import os
|
||||
import signal
|
||||
import ctypes
|
||||
|
||||
from PySide6 import QtCore
|
||||
from PySide6.QtWidgets import QApplication
|
||||
from PySide6.QtCore import QTimer
|
||||
from PySide6.QtCore import QTimer, QLibraryInfo, QTranslator, QLocale
|
||||
from PySide6.QtGui import QIcon
|
||||
import sys
|
||||
|
||||
@@ -40,6 +41,17 @@ if __name__ == "__main__":
|
||||
# if translator.load(QLocale("de"), "messages_de.ts"):
|
||||
# app.installTranslator(translator)
|
||||
|
||||
locale = os.environ['LANG'] if os.environ['LANG'] else "en"
|
||||
|
||||
path = QLibraryInfo.location(QLibraryInfo.TranslationsPath)
|
||||
translator = QTranslator(app)
|
||||
if translator.load(QLocale(locale), 'qtbase', '_', path):
|
||||
app.installTranslator(translator)
|
||||
translator = QTranslator(app)
|
||||
path = './translations'
|
||||
if translator.load(QLocale(locale), 'messages', '_', path):
|
||||
app.installTranslator(translator)
|
||||
|
||||
# workaround to make signals work in QT apps.
|
||||
# They do not work out of the box, because the main thread
|
||||
# is running in C++ code once app.exec() is executed
|
||||
@@ -55,6 +67,8 @@ if __name__ == "__main__":
|
||||
PluginRegistry.load_plugin("LogFilePlugin")
|
||||
PluginRegistry.load_plugin("NotesPlugin")
|
||||
|
||||
PluginRegistry.execute("set_translator", lambda string: translator.tr(string))
|
||||
|
||||
window = PluginRegistry.execute_single("create_main_window")
|
||||
RavenUI.window = window
|
||||
window.show()
|
||||
|
||||
Reference in New Issue
Block a user