diff --git a/ovos_bus_client/session.py b/ovos_bus_client/session.py index 7bf2baa..1305cc7 100644 --- a/ovos_bus_client/session.py +++ b/ovos_bus_client/session.py @@ -7,7 +7,7 @@ from ovos_config.config import Configuration from ovos_config.locale import get_default_lang from ovos_utils.log import LOG, log_deprecation - +from ovos_utils.lang import standardize_lang_tag from ovos_bus_client.message import dig_for_message, Message @@ -297,7 +297,7 @@ def __init__(self, session_id: str = None, Configuration().get("skills", {}).get("blacklisted_skills", [])) self.blacklisted_intents = (blacklisted_intents or Configuration().get("intents", {}).get("blacklisted_intents", [])) - self.lang = lang or get_default_lang() + self.lang = standardize_lang_tag(lang or get_default_lang()) self.system_unit = system_unit or Configuration().get("system_unit", "metric") self.date_format = date_format or Configuration().get("date_format", "DMY") self.time_format = time_format or Configuration().get("time_format", "full") diff --git a/ovos_bus_client/util/__init__.py b/ovos_bus_client/util/__init__.py index 5316f83..a89aa8d 100644 --- a/ovos_bus_client/util/__init__.py +++ b/ovos_bus_client/util/__init__.py @@ -20,6 +20,7 @@ from ovos_config.config import read_mycroft_config from ovos_config.locale import get_default_lang from ovos_utils.json_helper import merge_dict +from ovos_utils.lang import standardize_lang_tag from ovos_bus_client import MessageBusClient from ovos_bus_client.message import dig_for_message, Message from ovos_bus_client.session import SessionManager @@ -39,14 +40,14 @@ def get_message_lang(message=None): # old style lang param lang = message.data.get("lang") or message.context.get("lang") if lang: - return lang + return standardize_lang_tag(lang) # new style session lang if "session_id" in message.context or "session" in message.context: sess = SessionManager.get(message) return sess.lang - return get_default_lang() + return standardize_lang_tag(get_default_lang()) def get_websocket(host, port, route='/', ssl=False, threaded=True): diff --git a/requirements.txt b/requirements.txt index 0e006b1..140b27e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ ovos-config>=0.0.12,<1.0.0 -ovos-utils>=0.0.38,<1.0.0 +ovos-utils>=0.3.5,<1.0.0 websocket-client>=0.54.0 pyee>=8.1.0, < 12.0.0 orjson diff --git a/test/unittests/test_message.py b/test/unittests/test_message.py index a3b285a..423b257 100644 --- a/test/unittests/test_message.py +++ b/test/unittests/test_message.py @@ -162,16 +162,16 @@ def test_no_lang_in_message(self): """No lang in message should result in lang from active locale.""" setup_locale("it-it") msg = Message('test msg', data={}) - self.assertEqual(get_message_lang(msg), 'it-it') + self.assertEqual(get_message_lang(msg), 'it-IT') setup_locale("en-us") - self.assertEqual(get_message_lang(msg), 'en-us') + self.assertEqual(get_message_lang(msg), 'en-US') def test_lang_exists(self): """Message has a lang code in data, it should be used.""" msg = Message('test msg', data={'lang': 'de-de'}) - self.assertEqual(get_message_lang(msg), 'de-de') - msg = Message('test msg', data={'lang': 'sv-se'}) - self.assertEqual(get_message_lang(msg), 'sv-se') + self.assertEqual(get_message_lang(msg), 'de-DE') + msg = Message('test msg', data={'lang': 'sv-SE'}) + self.assertEqual(get_message_lang(msg), 'sv-SE') class TestCollectionMessage(unittest.TestCase):