From ac1e6fe5b7431123f8f1f0d4e445d2b601fa7ef2 Mon Sep 17 00:00:00 2001 From: Ryan Holmes Date: Fri, 24 Jul 2020 20:42:47 -0400 Subject: [PATCH] Starting to generate list of languages dynamically --- gui/app.py | 4 ++-- gui/builtinPreferenceViews/pyfaGeneralPreferences.py | 9 ++++++--- service/settings.py | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/gui/app.py b/gui/app.py index bc0c1cc22..9abd11452 100644 --- a/gui/app.py +++ b/gui/app.py @@ -1,6 +1,7 @@ import wx import config import os + from logbook import Logger pyfalog = Logger(__name__) from service.settings import LocaleSettings @@ -63,7 +64,6 @@ class PyfaApp(wx.App): selLang = supLang[lang].wxLocale else: selLang = wx.LANGUAGE_ENGLISH_US - if self.locale: assert sys.getrefcount(self.locale) <= 2 del self.locale @@ -72,7 +72,7 @@ class PyfaApp(wx.App): pyfalog.debug("Setting language to: " + lang) self.locale = wx.Locale(selLang) if self.locale.IsOk(): - success = self.locale.AddCatalog(langDomain, selLang) + success = self.locale.AddCatalog(langDomain) if not success: print("Langauage catalog not successfully loaded") diff --git a/gui/builtinPreferenceViews/pyfaGeneralPreferences.py b/gui/builtinPreferenceViews/pyfaGeneralPreferences.py index 18c2aa000..9039f6eee 100644 --- a/gui/builtinPreferenceViews/pyfaGeneralPreferences.py +++ b/gui/builtinPreferenceViews/pyfaGeneralPreferences.py @@ -102,8 +102,9 @@ class PFGeneralPref(PreferenceView): self.stLangLabel.Wrap(-1) langSizer.Add(self.stLangLabel, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) - self.langChoices = self.localeSettings.supported_langauges.keys() - self.chLang = wx.Choice(panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, sorted([x for x in self.langChoices]), 0) + self.langChoices = sorted([wx.Locale.FindLanguageInfo(x) for x in wx.Translations.Get().GetAvailableTranslations('lang')], key=lambda x: x.Description) + + self.chLang = wx.Choice(panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, [x.Description for x in self.langChoices], 0) self.chLang.Bind(wx.EVT_CHOICE, self.onLangSelection) self.chLang.SetStringSelection(self.localeSettings.get('locale')) @@ -167,7 +168,9 @@ class PFGeneralPref(PreferenceView): panel.Layout() def onLangSelection(self, event): - self.localeSettings.set('locale', self.chLang.GetString(self.chLang.GetSelection())) + selection = self.chLang.GetSelection() + locale = self.langChoices[selection] + self.localeSettings.set('locale', locale.CanonicalName) def onEosLangSelection(self, event): self.localeSettings.set('eos_locale', self.chEosLang.GetString(self.chEosLang.GetSelection())) diff --git a/service/settings.py b/service/settings.py index ea172ca21..3930fe702 100644 --- a/service/settings.py +++ b/service/settings.py @@ -576,6 +576,7 @@ class LocaleSettings: def get_eos_locale(self): """gets the effective value of the setting""" val = self.settings['eos_locale'] + return 'en' return val if val != self.defaults['eos_locale'] else self.supported_langauges.get(self.settings['locale'], 'en').eosLang def set(self, key, value):