Only default to system locale if a translation file exists (#1564)

This commit is contained in:
Veronica Berglyd Olsen
2023-11-02 23:34:42 +01:00
parent 6df591c803
commit 08a012ef8d
2 changed files with 11 additions and 9 deletions
+8 -6
View File
@@ -81,10 +81,12 @@ class Config:
# Localisation
# Note that these paths must be strings
self._qLocale = QLocale.system()
self._qtTrans = {}
self._nwLangPath = self._appPath / "assets" / "i18n"
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
pdfDocs = self._appPath / "assets" / "manual.pdf"
@@ -427,7 +429,7 @@ class Config:
else:
return []
for qmFile in Path(self._nwLangPath).iterdir():
for qmFile in self._nwLangPath.iterdir():
qmName = qmFile.name
if not (qmFile.is_file() and qmName.startswith(fPre) and qmName.endswith(fExt)):
continue
@@ -495,8 +497,8 @@ class Config:
self._qtTrans = {}
langList = [
(self._qtLangPath, "qtbase"), # Qt 5.x
(self._nwLangPath, "nw"), # novelWriter
(self._qtLangPath, "qtbase"), # Qt 5.x
(str(self._nwLangPath), "nw"), # novelWriter
]
for lngPath, lngBase in langList:
for lngCode in self._qLocale.uiLanguages():
+3 -3
View File
@@ -166,21 +166,21 @@ def testBaseConfig_Localisation(fncPath, tstPaths):
i18nDir = fncPath / "i18n"
i18nDir.mkdir()
tstConf._nwLangPath = str(i18nDir)
tstConf._nwLangPath = i18nDir
copyfile(tstPaths.filesDir / "nw_en_GB.qm", i18nDir / "nw_en_GB.qm")
writeFile(i18nDir / "nw_en_GB.ts", "")
writeFile(i18nDir / "nw_abcd.qm", "")
tstApp = MockApp()
tstConf.initLocalisation(tstApp)
tstConf.initLocalisation(tstApp) # type: ignore
# Check Lists
theList = tstConf.listLanguages(tstConf.LANG_NW)
assert theList == [("en_GB", "British English")]
theList = tstConf.listLanguages(tstConf.LANG_PROJ)
assert theList == [("en_GB", "British English")]
theList = tstConf.listLanguages(None)
theList = tstConf.listLanguages(None) # type: ignore
assert theList == []
# Add Language