From fac0436dda5cad4f46a0666d8f8121e35ab9ec93 Mon Sep 17 00:00:00 2001 From: Shadi Naif Date: Mon, 18 Mar 2024 21:55:15 +0300 Subject: [PATCH] feat!: remove Transifex calls for FC-0012 - OEP-58 (#445) --- .tx/config | 9 ------- CHANGELOG.rst | 8 +++++++ README.rst | 11 --------- lti_consumer/__init__.py | 2 +- lti_consumer/conf/locale/config.yaml | 11 --------- lti_consumer/lti_xblock.py | 35 ++++++++++++---------------- 6 files changed, 24 insertions(+), 52 deletions(-) delete mode 100644 .tx/config diff --git a/.tx/config b/.tx/config deleted file mode 100644 index 15bc669f..00000000 --- a/.tx/config +++ /dev/null @@ -1,9 +0,0 @@ -[main] -host = https://www.transifex.com - -[o:open-edx:p:xblocks:r:lti-consumer] -file_filter = lti_consumer/translations//LC_MESSAGES/text.po -source_file = lti_consumer/translations/en/LC_MESSAGES/text.po -source_lang = en -type = PO - diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 37d1839b..14423aba 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -15,6 +15,14 @@ Please See the `releases tab `_ and run this command while -inside project root directory: - -.. code:: bash - - $ tx pull -f --mode=reviewed - Further Development Info ------------------------ diff --git a/lti_consumer/__init__.py b/lti_consumer/__init__.py index cd9ee742..0ba711e2 100644 --- a/lti_consumer/__init__.py +++ b/lti_consumer/__init__.py @@ -4,4 +4,4 @@ from .apps import LTIConsumerApp from .lti_xblock import LtiConsumerXBlock -__version__ = '9.8.3' +__version__ = '9.9.0' diff --git a/lti_consumer/conf/locale/config.yaml b/lti_consumer/conf/locale/config.yaml index 19ef2783..cc218b26 100644 --- a/lti_consumer/conf/locale/config.yaml +++ b/lti_consumer/conf/locale/config.yaml @@ -2,17 +2,6 @@ locales: - en # English - Source Language - - ar # Arabic - - es_419 # Spanish (Latin America) - - fr # French - - he # Hebrew - - hi # Hindi - - ja_JP # Japanese (Japan) - - ko_KR # Korean (Korea) - - pt_BR # Portuguese (Brazil) - - pt_PT # Portuguese (Portugal) - - ru # Russian - - zh_CN # Chinese (China) # Directories we don't search for strings. ignore_dirs: diff --git a/lti_consumer/lti_xblock.py b/lti_consumer/lti_xblock.py index bf18b4b2..08789041 100644 --- a/lti_consumer/lti_xblock.py +++ b/lti_consumer/lti_xblock.py @@ -55,11 +55,10 @@ import urllib.parse from collections import namedtuple from importlib import import_module -import pkg_resources import bleach from django.conf import settings -from django.utils import timezone, translation +from django.utils import timezone from web_fragments.fragment import Fragment from webob import Response @@ -257,6 +256,7 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock): """ block_settings_key = 'lti_consumer' + i18n_js_namespace = 'XBlockLtiConsumerI18N' display_name = String( display_name=_("Display Name"), @@ -662,20 +662,15 @@ def workbench_scenarios(): ] return scenarios - @staticmethod - def _get_statici18n_js_url(loader): # pragma: no cover - """ - Returns the Javascript translation file for the currently selected language, if any found by - `pkg_resources` - """ - lang_code = translation.get_language() - if not lang_code: - return None - text_js = 'public/js/translations/{lang_code}/text.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) + def _get_statici18n_js_url(self): + """ + Return the JavaScript translation file provided by the XBlockI18NService. + """ + if i18n_service := self.runtime.service(self, 'i18n'): + if url_getter_func := getattr(i18n_service, 'get_javascript_i18n_catalog_url', None): + if javascript_url := url_getter_func(self): + return javascript_url + return None def validate_field_data(self, validation, data): @@ -1197,9 +1192,9 @@ def author_view(self, context): ) fragment.add_css(loader.load_unicode('static/css/student.css')) fragment.add_javascript(loader.load_unicode('static/js/xblock_lti_consumer.js')) - statici18n_js_url = self._get_statici18n_js_url(loader) + statici18n_js_url = self._get_statici18n_js_url() if statici18n_js_url: - fragment.add_javascript_url(self.runtime.local_resource_url(self, statici18n_js_url)) + fragment.add_javascript_url(statici18n_js_url) fragment.initialize_js('LtiConsumerXBlock') return fragment @@ -1224,9 +1219,9 @@ def student_view(self, context): fragment.add_content(loader.render_mako_template('/templates/html/student.html', context)) fragment.add_css(loader.load_unicode('static/css/student.css')) fragment.add_javascript(loader.load_unicode('static/js/xblock_lti_consumer.js')) - statici18n_js_url = self._get_statici18n_js_url(loader) + statici18n_js_url = self._get_statici18n_js_url() if statici18n_js_url: - fragment.add_javascript_url(self.runtime.local_resource_url(self, statici18n_js_url)) + fragment.add_javascript_url(statici18n_js_url) fragment.initialize_js('LtiConsumerXBlock') return fragment