Rewrite listLanguages function to add more checks and fix misidentification of default language
This commit is contained in:
+16
-7
@@ -394,14 +394,23 @@ class Config:
|
|||||||
return
|
return
|
||||||
|
|
||||||
def listLanguages(self):
|
def listLanguages(self):
|
||||||
langs = dict(map(lambda lang: (lang, QLocale(lang).nativeLanguageName().title()),
|
"""List localisation files in the i18n folder. The default GUI
|
||||||
map(lambda v: v[0][3:],
|
language 'en_GB' is British English.
|
||||||
filter(lambda v: v[0].startswith("nw_") and v[1] == ".qm",
|
"""
|
||||||
map(os.path.splitext, os.listdir(self.nwLangPath))))))
|
langList = {
|
||||||
if "en" not in langs:
|
"en_GB": QLocale("en_GB").nativeLanguageName().title()
|
||||||
langs["en"] = QLocale("en").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):
|
def loadConfig(self):
|
||||||
"""Load preferences from file and replace default settings.
|
"""Load preferences from file and replace default settings.
|
||||||
|
|||||||
@@ -137,10 +137,11 @@ class GuiPreferencesGeneral(QWidget):
|
|||||||
# Look and Feel
|
# Look and Feel
|
||||||
# =============
|
# =============
|
||||||
self.mainForm.addGroupLabel(self.tr("Look and Feel"))
|
self.mainForm.addGroupLabel(self.tr("Look and Feel"))
|
||||||
|
minWidth = self.mainConf.pxInt(200)
|
||||||
|
|
||||||
## Select Locale
|
## Select Locale
|
||||||
self.guiLang = QComboBox()
|
self.guiLang = QComboBox()
|
||||||
self.guiLang.setMinimumWidth(self.mainConf.pxInt(200))
|
self.guiLang.setMinimumWidth(minWidth)
|
||||||
self.theLangs = self.mainConf.listLanguages()
|
self.theLangs = self.mainConf.listLanguages()
|
||||||
print(self.theLangs)
|
print(self.theLangs)
|
||||||
for lang, langName in self.theLangs:
|
for lang, langName in self.theLangs:
|
||||||
@@ -157,7 +158,7 @@ class GuiPreferencesGeneral(QWidget):
|
|||||||
|
|
||||||
## Select Theme
|
## Select Theme
|
||||||
self.guiTheme = QComboBox()
|
self.guiTheme = QComboBox()
|
||||||
self.guiTheme.setMinimumWidth(self.mainConf.pxInt(200))
|
self.guiTheme.setMinimumWidth(minWidth)
|
||||||
self.theThemes = self.theTheme.listThemes()
|
self.theThemes = self.theTheme.listThemes()
|
||||||
for themeDir, themeName in self.theThemes:
|
for themeDir, themeName in self.theThemes:
|
||||||
self.guiTheme.addItem(themeName, themeDir)
|
self.guiTheme.addItem(themeName, themeDir)
|
||||||
@@ -173,7 +174,7 @@ class GuiPreferencesGeneral(QWidget):
|
|||||||
|
|
||||||
## Select Icon Theme
|
## Select Icon Theme
|
||||||
self.guiIcons = QComboBox()
|
self.guiIcons = QComboBox()
|
||||||
self.guiIcons.setMinimumWidth(self.mainConf.pxInt(200))
|
self.guiIcons.setMinimumWidth(minWidth)
|
||||||
self.theIcons = self.theTheme.theIcons.listThemes()
|
self.theIcons = self.theTheme.theIcons.listThemes()
|
||||||
for iconDir, iconName in self.theIcons:
|
for iconDir, iconName in self.theIcons:
|
||||||
self.guiIcons.addItem(iconName, iconDir)
|
self.guiIcons.addItem(iconName, iconDir)
|
||||||
|
|||||||
Reference in New Issue
Block a user