Fix i18n issues (#1565)

This commit is contained in:
Veronica Berglyd Olsen
2023-11-02 23:44:53 +01:00
committed by GitHub
4 changed files with 15 additions and 11 deletions
+8 -6
View File
@@ -81,10 +81,12 @@ class Config:
# Localisation # Localisation
# Note that these paths must be strings # Note that these paths must be strings
self._qLocale = QLocale.system() self._nwLangPath = self._appPath / "assets" / "i18n"
self._qtTrans = {}
self._qtLangPath = QLibraryInfo.location(QLibraryInfo.TranslationsPath) self._qtLangPath = QLibraryInfo.location(QLibraryInfo.TranslationsPath)
self._nwLangPath = str(self._appPath / "assets" / "i18n")
wantedLocale = self._nwLangPath / f"nw_{QLocale.system().name()}.qm"
self._qLocale = QLocale.system() if wantedLocale.exists() else QLocale("en_GB")
self._qtTrans = {}
# PDF Manual # PDF Manual
pdfDocs = self._appPath / "assets" / "manual.pdf" pdfDocs = self._appPath / "assets" / "manual.pdf"
@@ -427,7 +429,7 @@ class Config:
else: else:
return [] return []
for qmFile in Path(self._nwLangPath).iterdir(): for qmFile in self._nwLangPath.iterdir():
qmName = qmFile.name qmName = qmFile.name
if not (qmFile.is_file() and qmName.startswith(fPre) and qmName.endswith(fExt)): if not (qmFile.is_file() and qmName.startswith(fPre) and qmName.endswith(fExt)):
continue continue
@@ -495,8 +497,8 @@ class Config:
self._qtTrans = {} self._qtTrans = {}
langList = [ langList = [
(self._qtLangPath, "qtbase"), # Qt 5.x (self._qtLangPath, "qtbase"), # Qt 5.x
(self._nwLangPath, "nw"), # novelWriter (str(self._nwLangPath), "nw"), # novelWriter
] ]
for lngPath, lngBase in langList: for lngPath, lngBase in langList:
for lngCode in self._qLocale.uiLanguages(): for lngCode in self._qLocale.uiLanguages():
+2 -2
View File
@@ -32,7 +32,7 @@ from enum import Enum
from typing import Iterable from typing import Iterable
from pathlib import Path from pathlib import Path
from PyQt5.QtCore import QT_TRANSLATE_NOOP from PyQt5.QtCore import QT_TRANSLATE_NOOP, QCoreApplication
from novelwriter import CONFIG from novelwriter import CONFIG
from novelwriter.enum import nwBuildFmt from novelwriter.enum import nwBuildFmt
@@ -209,7 +209,7 @@ class BuildSettings:
@staticmethod @staticmethod
def getLabel(key: str) -> str: def getLabel(key: str) -> str:
"""Extract the GUI label for a specific setting.""" """Extract the GUI label for a specific setting."""
return SETTINGS_LABELS.get(key, "ERROR") return QCoreApplication.translate("Builds", SETTINGS_LABELS.get(key, "ERROR"))
def getStr(self, key: str) -> str: def getStr(self, key: str) -> str:
"""Type safe value access for strings.""" """Type safe value access for strings."""
+2
View File
@@ -176,6 +176,8 @@ class GuiPreferencesGeneral(QWidget):
for lang, langName in theLangs: for lang, langName in theLangs:
self.guiLocale.addItem(langName, lang) self.guiLocale.addItem(langName, lang)
langIdx = self.guiLocale.findData(CONFIG.guiLocale) langIdx = self.guiLocale.findData(CONFIG.guiLocale)
if langIdx < 0:
langIdx = self.guiLocale.findData("en_GB")
if langIdx != -1: if langIdx != -1:
self.guiLocale.setCurrentIndex(langIdx) self.guiLocale.setCurrentIndex(langIdx)
+3 -3
View File
@@ -166,21 +166,21 @@ def testBaseConfig_Localisation(fncPath, tstPaths):
i18nDir = fncPath / "i18n" i18nDir = fncPath / "i18n"
i18nDir.mkdir() i18nDir.mkdir()
tstConf._nwLangPath = str(i18nDir) tstConf._nwLangPath = i18nDir
copyfile(tstPaths.filesDir / "nw_en_GB.qm", i18nDir / "nw_en_GB.qm") copyfile(tstPaths.filesDir / "nw_en_GB.qm", i18nDir / "nw_en_GB.qm")
writeFile(i18nDir / "nw_en_GB.ts", "") writeFile(i18nDir / "nw_en_GB.ts", "")
writeFile(i18nDir / "nw_abcd.qm", "") writeFile(i18nDir / "nw_abcd.qm", "")
tstApp = MockApp() tstApp = MockApp()
tstConf.initLocalisation(tstApp) tstConf.initLocalisation(tstApp) # type: ignore
# Check Lists # Check Lists
theList = tstConf.listLanguages(tstConf.LANG_NW) theList = tstConf.listLanguages(tstConf.LANG_NW)
assert theList == [("en_GB", "British English")] assert theList == [("en_GB", "British English")]
theList = tstConf.listLanguages(tstConf.LANG_PROJ) theList = tstConf.listLanguages(tstConf.LANG_PROJ)
assert theList == [("en_GB", "British English")] assert theList == [("en_GB", "British English")]
theList = tstConf.listLanguages(None) theList = tstConf.listLanguages(None) # type: ignore
assert theList == [] assert theList == []
# Add Language # Add Language