Browse Source

Search and load translation files at frontend startup

Signed-off-by: falkTX <falktx@falktx.com>
tags/v2.3.0-RC1
JP Cimalando falkTX <falktx@falktx.com> 5 years ago
parent
commit
c7edf7c915
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
1 changed files with 21 additions and 1 deletions
  1. +21
    -1
      source/frontend/carla_app.py

+ 21
- 1
source/frontend/carla_app.py View File

@@ -30,7 +30,7 @@ from ctypes import CDLL, RTLD_GLOBAL
# ------------------------------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------------------------------
# Imports (PyQt5) # Imports (PyQt5)


from PyQt5.QtCore import QT_VERSION, Qt, QCoreApplication
from PyQt5.QtCore import QT_VERSION, Qt, QCoreApplication, QLibraryInfo, QLocale, QSettings, QTranslator
from PyQt5.QtGui import QColor, QIcon, QPalette from PyQt5.QtGui import QColor, QIcon, QPalette
from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QApplication


@@ -77,6 +77,22 @@ class CarlaApplication():
else: else:
stylesDir = "" stylesDir = ""


# Set up translations
currentLocale = QLocale()
appTranslator = QTranslator()
sysTranslator = None
pathTranslations = os.path.join(pathResources, "translations")
if appTranslator.load(currentLocale, "carla", "_", pathTranslations):
sysTranslator = QTranslator()
pathSysTranslations = pathTranslations
if not sysTranslator.load(currentLocale, "qt", "_", pathSysTranslations):
pathSysTranslations = QLibraryInfo.location(QLibraryInfo.TranslationsPath)
sysTranslator.load(currentLocale, "qt", "_", pathSysTranslations)
else:
appTranslator = None
self.fAppTranslator = appTranslator
self.fSysTranslator = sysTranslator

# base settings # base settings
settings = QSafeSettings("falkTX", appName) settings = QSafeSettings("falkTX", appName)
useProTheme = MACOS or settings.value(CARLA_KEY_MAIN_USE_PRO_THEME, CARLA_DEFAULT_MAIN_USE_PRO_THEME, bool) useProTheme = MACOS or settings.value(CARLA_KEY_MAIN_USE_PRO_THEME, CARLA_DEFAULT_MAIN_USE_PRO_THEME, bool)
@@ -138,6 +154,10 @@ class CarlaApplication():
self.fApp.setApplicationVersion(VERSION) self.fApp.setApplicationVersion(VERSION)
self.fApp.setOrganizationName("falkTX") self.fApp.setOrganizationName("falkTX")


if self.fAppTranslator is not None:
self.fApp.installTranslator(self.fAppTranslator)
self.fApp.installTranslator(self.fSysTranslator)

if gCarla.nogui: if gCarla.nogui:
return return




Loading…
Cancel
Save