diff --git a/nw/config.py b/nw/config.py index 5cf71b85..88984d5a 100644 --- a/nw/config.py +++ b/nw/config.py @@ -393,6 +393,16 @@ 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() + + return sorted(langs.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 8234ebf3..7e8bbd01 100644 --- a/nw/gui/preferences.py +++ b/nw/gui/preferences.py @@ -138,6 +138,23 @@ class GuiPreferencesGeneral(QWidget): # ============= self.mainForm.addGroupLabel(self.tr("Look and Feel")) + ## Select Locale + self.guiLang = QComboBox() + self.guiLang.setMinimumWidth(self.mainConf.pxInt(200)) + self.theLangs = self.mainConf.listLanguages() + print(self.theLangs) + for lang, langName in self.theLangs: + self.guiLang.addItem(langName, lang) + langIdx = self.guiLang.findData(self.mainConf.guiLang) + if langIdx != -1: + self.guiLang.setCurrentIndex(langIdx) + + self.mainForm.addRow( + self.tr("Main GUI language"), + self.guiLang, + self.tr("Changing this requires restarting novelWriter.") + ) + ## Select Theme self.guiTheme = QComboBox() self.guiTheme.setMinimumWidth(self.mainConf.pxInt(200)) @@ -240,6 +257,7 @@ class GuiPreferencesGeneral(QWidget): def saveValues(self): """Save the values set for this tab. """ + guiLang = self.guiLang.currentData() guiTheme = self.guiTheme.currentData() guiIcons = self.guiIcons.currentData() guiDark = self.guiDark.isChecked() @@ -248,12 +266,14 @@ class GuiPreferencesGeneral(QWidget): # Check if restart is needed needsRestart = False + needsRestart |= self.mainConf.guiLang != guiLang needsRestart |= self.mainConf.guiTheme != guiTheme needsRestart |= self.mainConf.guiIcons != guiIcons needsRestart |= self.mainConf.guiDark != guiDark needsRestart |= self.mainConf.guiFont != guiFont needsRestart |= self.mainConf.guiFontSize != guiFontSize + self.mainConf.guiLang = guiLang self.mainConf.guiTheme = guiTheme self.mainConf.guiIcons = guiIcons self.mainConf.guiDark = guiDark