From b62182ec2c08f1dcb4cade1e3e7756cd6b72a8b1 Mon Sep 17 00:00:00 2001 From: Jillian Vogel Date: Thu, 30 Jan 2025 18:36:30 +1030 Subject: [PATCH 1/2] feat: set the session locale from the Open edX preferred language If the full language locale is supported, use it. Otherwise, use the language part of the locale. --- .../pythonpath/openedx_sso_security_manager.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tutoraspects/templates/aspects/apps/superset/pythonpath/openedx_sso_security_manager.py b/tutoraspects/templates/aspects/apps/superset/pythonpath/openedx_sso_security_manager.py index 06ea382ba..3ac837095 100644 --- a/tutoraspects/templates/aspects/apps/superset/pythonpath/openedx_sso_security_manager.py +++ b/tutoraspects/templates/aspects/apps/superset/pythonpath/openedx_sso_security_manager.py @@ -70,9 +70,21 @@ def get_preferences(self, username): if locale_preference not in current_app.config["DASHBOARD_LOCALES"]: log.warning( - f"Language {locale_preference} is not supported by Superset" + f"Locale {locale_preference} is not supported by Superset DASHBOARD_LOCALES" ) - return locale_preference + + # Use the full locale if it's supported + if locale_preference in current_app.config["LANGUAGES"]: + session["locale"] = locale_preference + else: + # Otherwise, try just the language part of the locale + lang_preference = locale_preference.split('_')[0] + if lang_preference in current_app.config["LANGUAGES"]: + session["locale"] = lang_preference + else: + log.warning( + f"Locale {locale_preference} and language {lang_preference} are not supported by Superset LANGUAGES" + ) return locale_preference From 7b1d42252a53d32714668028e4cdbb0fbba3089c Mon Sep 17 00:00:00 2001 From: Jillian Vogel Date: Wed, 19 Feb 2025 10:46:40 +1030 Subject: [PATCH 2/2] feat: pass LANGUAGE_CODE|lower through to BABEL_DEFAULT_LOCALE if LANGUAGE_CODE is one of the SUPERSET_SUPPORTED_LANGUAGES --- .../aspects/apps/superset/pythonpath/superset_config.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tutoraspects/templates/aspects/apps/superset/pythonpath/superset_config.py b/tutoraspects/templates/aspects/apps/superset/pythonpath/superset_config.py index 02889a339..f8376dd85 100644 --- a/tutoraspects/templates/aspects/apps/superset/pythonpath/superset_config.py +++ b/tutoraspects/templates/aspects/apps/superset/pythonpath/superset_config.py @@ -170,7 +170,13 @@ class CeleryConfig(object): } } {% endif %} + +{% if LANGUAGE_CODE|lower in SUPERSET_SUPPORTED_LANGUAGES %} +BABEL_DEFAULT_LOCALE = "{{ LANGUAGE_CODE|lower }}" +{% else %} BABEL_DEFAULT_LOCALE = "en" +print(f"LANGUAGE_CODE='{{ LANGUAGE_CODE|lower }}' not supported by Superset, falling back to 'en'") +{% endif %} {{ patch('superset-config')}}