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:standardize_lang #128

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions ovos_bus_client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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")
Expand Down
5 changes: 3 additions & 2 deletions ovos_bus_client/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions test/unittests/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading