From cc0d6465d6b6955378fa85cbe198cc541539999e Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Tue, 5 Dec 2023 15:31:18 +0600 Subject: [PATCH] Do not crash on failure to fetch localization percentage --- gui/builtinPreferenceViews/pyfaGeneralPreferences.py | 2 +- service/settings.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gui/builtinPreferenceViews/pyfaGeneralPreferences.py b/gui/builtinPreferenceViews/pyfaGeneralPreferences.py index f1e82e219..40c17083b 100644 --- a/gui/builtinPreferenceViews/pyfaGeneralPreferences.py +++ b/gui/builtinPreferenceViews/pyfaGeneralPreferences.py @@ -40,7 +40,7 @@ class PFGeneralPref(PreferenceView): langSizer = wx.BoxSizer(wx.HORIZONTAL) - self.langChoices = sorted([langInfo for lang, langInfo in LocaleSettings.supported_langauges().items()], key=lambda x: x.Description) + self.langChoices = sorted([langInfo for lang, langInfo in LocaleSettings.supported_languages().items()], key=lambda x: x.Description) pyfaLangsEnabled = bool(self.langChoices) if pyfaLangsEnabled: diff --git a/service/settings.py b/service/settings.py index c974a8a17..f651f5206 100644 --- a/service/settings.py +++ b/service/settings.py @@ -559,7 +559,7 @@ class LocaleSettings: with open(os.path.join(config.pyfaPath, 'locale', 'progress.json'), "r") as f: self.progress_data = json.load(f) except FileNotFoundError: - self.progress_data = None + self.progress_data = {} @classmethod def getInstance(cls): @@ -568,14 +568,14 @@ class LocaleSettings: return cls._instance def get_progress(self, lang): - if self.progress_data is None: + if not self.progress_data: return None if lang == self.defaults['locale']: return None - return self.progress_data[lang] + return self.progress_data.get(lang) @classmethod - def supported_langauges(cls): + def supported_languages(cls): """Requires the application to be initialized, otherwise wx.Translation isn't set.""" pyfalog.info(f'using "{config.CATALOG}" to fetch languages, relatively base path "{os.getcwd()}"') return {x: wx.Locale.FindLanguageInfo(x) for x in wx.Translations.Get().GetAvailableTranslations(config.CATALOG)} @@ -590,6 +590,6 @@ class LocaleSettings: return val if val != self.defaults['eos_locale'] else self.settings['locale'].split("_")[0] def set(self, key, value): - if key == 'locale' and value not in self.supported_langauges(): + if key == 'locale' and value not in self.supported_languages(): self.settings[key] = self.DEFAULT self.settings[key] = value