Skip to content

Commit

Permalink
fix/untangle_from_LF (#88)
Browse files Browse the repository at this point in the history
* fix/untangle_from_LF

untangles configuration from lingua-franca, ovos-config should be the source of truth for everything config related

fix: LF was optional, but if installed would stop core from loading if configured language was unsupported

* Update locale.py
  • Loading branch information
JarbasAl authored Dec 23, 2023
1 parent ae24347 commit f9ceb17
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions ovos_config/locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ def get_full_lang_code(lang):

def get_primary_lang_code(config=None):
global _lang
if LF:
return LF.get_primary_lang_code()
if not _lang:
config = config or ovos_config.Configuration()
_lang = config.get("lang", "en-us")
Expand All @@ -65,20 +63,24 @@ def get_default_lang(config=None):
@return: lowercase BCP-47 language code
"""
global _lang
if LF and LF.get_default_loc():
return LF.get_default_loc()
if not _lang:
config = config or ovos_config.Configuration()
_lang = config.get("lang", "en-us")
return _lang


def set_default_lang(lang):
""" setup default language across OVOS packages
currently only configures lingua-franca language, in the future
other hooks may be added if we need to perform this operation globally"""
global _lang
_lang = lang
if LF:
LF.set_default_lang(lang)

try:
LF.set_default_lang(lang)
except:
pass

def get_config_tz():
code = ovos_config.Configuration()["location"]["timezone"]["code"]
Expand All @@ -91,7 +93,10 @@ def get_default_tz():


def set_default_tz(tz=None):
""" configure LF """
""" configure timezone across OVOS packages
currently only configures lingua-franca, in the future
other hooks may be added if we need to perform this operation globally """
global _default_tz
tz = tz or get_config_tz() or tzlocal()
_default_tz = tz
Expand All @@ -104,13 +109,27 @@ def set_default_tz(tz=None):


def load_languages(langs):
""" load and configure lang specific resources across OVOS packages
currently only loads lingua-franca language data, in the future
other hooks may be added if we need to perform this operation globally"""
if LF:
LF.load_languages(langs)
try:
LF.load_languages(langs)
except:
pass


def load_language(lang):
""" load and configure lang specific resources across OVOS packages
currently only loads lingua-franca language data, in the future
other hooks may be added if we need to perform this operation globally"""
if LF:
LF.load_language(lang)
try:
LF.load_language(lang)
except:
pass


def get_valid_languages():
Expand All @@ -121,6 +140,10 @@ def get_valid_languages():


def setup_locale(lang=None, tz=None):
""" setup default language, timezone and other locale data across OVOS packages
currently only configures lingua-franca, in the future
other hooks may be added if we need to perform this operation globally"""
lang_code = lang or ovos_config.Configuration().get("lang", "en-us")
valid_langs = get_valid_languages()
# load any lang specific resources
Expand Down

0 comments on commit f9ceb17

Please sign in to comment.