From 7591095f2a2a367c8ce4f8e8c143755d4142529a Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Wed, 17 Feb 2021 09:28:25 +0100 Subject: [PATCH] Rewrite listLanguages function to add more checks and fix misidentification of default language --- nw/config.py | 23 ++++++++++++++++------- nw/gui/preferences.py | 7 ++++--- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/nw/config.py b/nw/config.py index 88984d5a..618bfd3c 100644 --- a/nw/config.py +++ b/nw/config.py @@ -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. diff --git a/nw/gui/preferences.py b/nw/gui/preferences.py index 7e8bbd01..4e9a2627 100644 --- a/nw/gui/preferences.py +++ b/nw/gui/preferences.py @@ -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)