Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/untangle_from_LF #88

Merged
merged 2 commits into from
Dec 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading