From 3664cdf795d999d9643896127f1be51cadb1137a Mon Sep 17 00:00:00 2001 From: Shadi Naif Date: Thu, 1 Jun 2023 14:49:11 +0300 Subject: [PATCH] Fixes by Shadi for issues found during devstack tests --- cms/envs/devstack.py | 1 + xmodule/modulestore/django.py | 27 ++++++++------------------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/cms/envs/devstack.py b/cms/envs/devstack.py index 3364d42b9797..f13e8873fef1 100644 --- a/cms/envs/devstack.py +++ b/cms/envs/devstack.py @@ -22,6 +22,7 @@ CMS_BASE = 'localhost:18010' SESSION_COOKIE_NAME = 'studio_sessionid' +XBLOCK_TRANSLATIONS_DIRECTORY = '/edx/app/edxapp/edx-platform' ################################ LOGGERS ###################################### diff --git a/xmodule/modulestore/django.py b/xmodule/modulestore/django.py index eb078eed2774..48120dd8707b 100644 --- a/xmodule/modulestore/django.py +++ b/xmodule/modulestore/django.py @@ -379,7 +379,7 @@ def __init__(self, block=None): """ self.translator = django.utils.translation if block: - xblock_domain = 'text' + xblock_domain = 'django' selected_language = get_language() xblock_locale_path = self.get_python_locale_directory(block) @@ -394,7 +394,8 @@ def __init__(self, block=None): # Fall back to the default Django translator if the XBlock translator is not found. pass - def get_python_locale_directory(self, block): + @staticmethod + def get_python_locale_directory(block): """ Return the XBlock locale directory with support for OEP-58 updated translation infrastructure. @@ -409,17 +410,18 @@ def get_python_locale_directory(self, block): xblock_resource = xblock_class.__module__ if ENABLE_EXTERNAL_XBLOCK_TRANSLATIONS.is_enabled(): - xblock_module_name = xblock_resource.__name__ + xblock_module_name = xblock_resource xblock_locale_dir = 'conf/xblocks/locale' translations_dir = settings.XBLOCK_TRANSLATIONS_DIRECTORY - xblock_locale_path = path.join(translations_dir, xblock_locale_dir, xblock_module_name) + xblock_locale_path = path.join(translations_dir, xblock_locale_dir, xblock_module_name, 'conf/locale') else: xblock_locale_dir = 'translations' xblock_locale_path = resource_filename(xblock_resource, xblock_locale_dir) return xblock_locale_path - def get_javascript_locale_path(self, block): + @staticmethod + def get_javascript_locale_path(block): """ Return the XBlock compiled javascript i18n path with support for OEP-58 updated translation infrastructure. @@ -430,26 +432,13 @@ def get_javascript_locale_path(self, block): selected_language = get_language() if ENABLE_EXTERNAL_XBLOCK_TRANSLATIONS.is_enabled(): - xblock_module_name = xblock_resource.__name__ + xblock_module_name = xblock_resource xblock_locale_dir = 'conf/locale/{language}/LC_MESSAGES'.format(language=selected_language) - translations_dir = settings.XBLOCK_TRANSLATIONS_DIRECTORY xblock_locale_path = path.join(translations_dir, xblock_module_name, xblock_locale_dir, 'text.js') - if path.exists(xblock_locale_path): return xblock_locale_path - def get_javascript_resource_url(self, xblock_name): - lang_code = translation.get_language() - if not lang_code: - return None - text_js = f'public/js/xblock-translations/{xblock_name}/{lang_code}/django.js' - country_code = lang_code.split('-')[0] - for code in (translation.to_locale(lang_code), lang_code, country_code): - if pkg_resources.resource_exists(loader.module_name, text_js.format(lang_code=code)): - return text_js.format(lang_code=code) - return None - def __getattr__(self, name): name = 'gettext' if name == 'ugettext' else name return getattr(self.translator, name)