[core] Always initialize locale on startup

This commit is contained in:
derrod 2020-11-25 18:50:09 +01:00
parent 81463e6908
commit 3aeb48efdf

View file

@ -64,17 +64,12 @@ class LegendaryCore:
self.local_timezone = datetime.now().astimezone().tzinfo self.local_timezone = datetime.now().astimezone().tzinfo
self.language_code, self.country_code = ('en', 'US') self.language_code, self.country_code = ('en', 'US')
def get_locale(self): if locale := self.lgd.config.get('Legendary', 'locale', fallback=getdefaultlocale()[0]):
locale = self.lgd.config.get('Legendary', 'locale', fallback=getdefaultlocale()[0])
if locale:
try: try:
self.language_code, self.country_code = locale.split('-' if '-' in locale else '_') self.language_code, self.country_code = locale.split('-' if '-' in locale else '_')
self.log.debug(f'Set locale to {self.language_code}-{self.country_code}') self.log.debug(f'Set locale to {self.language_code}-{self.country_code}')
# adjust egs api language as well
# if egs is loaded make sure to override its language setting as well self.egs.language_code, self.egs.country_code = self.language_code, self.country_code
if self.egs:
self.egs.language_code, self.egs.country_code = self.language_code, self.country_code
except Exception as e: except Exception as e:
self.log.warning(f'Getting locale failed: {e!r}, falling back to using en-US.') self.log.warning(f'Getting locale failed: {e!r}, falling back to using en-US.')
else: else:
@ -227,8 +222,6 @@ class LegendaryCore:
def get_game_and_dlc_list(self, update_assets=True, def get_game_and_dlc_list(self, update_assets=True,
platform_override=None, platform_override=None,
skip_ue=True) -> (List[Game], Dict[str, Game]): skip_ue=True) -> (List[Game], Dict[str, Game]):
# resolve locale
self.get_locale()
_ret = [] _ret = []
_dlc = defaultdict(list) _dlc = defaultdict(list)
@ -364,7 +357,6 @@ class LegendaryCore:
language_code = self.lgd.config.get(app_name, 'language', fallback=language) language_code = self.lgd.config.get(app_name, 'language', fallback=language)
if not language_code: # fall back to system or config language if not language_code: # fall back to system or config language
self.get_locale()
language_code = self.language_code language_code = self.language_code
params.extend([ params.extend([