Rewrite listLanguages function to add more checks and fix misidentification of default language

This commit is contained in:
Veronica K. B. Olsen
2021-02-17 09:28:25 +01:00
parent 48575c09ca
commit 7591095f2a
2 changed files with 20 additions and 10 deletions
+16 -7
View File
@@ -394,14 +394,23 @@ class Config:
return
def listLanguages(self):
langs = dict(map(lambda lang: (lang, QLocale(lang).nativeLanguageName().title()),
map(lambda v: v[0][3:],
filter(lambda v: v[0].startswith("nw_") and v[1] == ".qm",
map(os.path.splitext, os.listdir(self.nwLangPath))))))
if "en" not in langs:
langs["en"] = QLocale("en").nativeLanguageName().title()
"""List localisation files in the i18n folder. The default GUI
language 'en_GB' is British English.
"""
langList = {
"en_GB": QLocale("en_GB").nativeLanguageName().title()
}
for qmFile in os.listdir(self.nwLangPath):
if not os.path.isfile(os.path.join(self.nwLangPath, qmFile)):
continue
if not qmFile.startswith("nw_") or not qmFile.endswith(".qm"):
continue
qmLang = qmFile[3:-3]
qmName = QLocale(qmLang).nativeLanguageName().title()
if qmLang and qmName:
langList[qmLang] = qmName
return sorted(langs.items(), key=lambda x: x[0])
return sorted(langList.items(), key=lambda x: x[0])
def loadConfig(self):
"""Load preferences from file and replace default settings.
+4 -3
View File
@@ -137,10 +137,11 @@ class GuiPreferencesGeneral(QWidget):
# Look and Feel
# =============
self.mainForm.addGroupLabel(self.tr("Look and Feel"))
minWidth = self.mainConf.pxInt(200)
## Select Locale
self.guiLang = QComboBox()
self.guiLang.setMinimumWidth(self.mainConf.pxInt(200))
self.guiLang.setMinimumWidth(minWidth)
self.theLangs = self.mainConf.listLanguages()
print(self.theLangs)
for lang, langName in self.theLangs:
@@ -157,7 +158,7 @@ class GuiPreferencesGeneral(QWidget):
## Select Theme
self.guiTheme = QComboBox()
self.guiTheme.setMinimumWidth(self.mainConf.pxInt(200))
self.guiTheme.setMinimumWidth(minWidth)
self.theThemes = self.theTheme.listThemes()
for themeDir, themeName in self.theThemes:
self.guiTheme.addItem(themeName, themeDir)
@@ -173,7 +174,7 @@ class GuiPreferencesGeneral(QWidget):
## Select Icon Theme
self.guiIcons = QComboBox()
self.guiIcons.setMinimumWidth(self.mainConf.pxInt(200))
self.guiIcons.setMinimumWidth(minWidth)
self.theIcons = self.theTheme.theIcons.listThemes()
for iconDir, iconName in self.theIcons:
self.guiIcons.addItem(iconName, iconDir)