Skip to content

Commit

Permalink
feat: use XBlockI18NService js translations
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadabuwardeh committed Jan 21, 2024
1 parent 44d0126 commit 78ed4ab
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ Please See the `releases tab <https://github.com/openedx/xblock-lti-consumer/rel
Unreleased
~~~~~~~~~~

Version 9.9.0 (2024-01-20)
---------------------------

* XBlockI18NService js translations support

9.8.1 - 2023-11-17
------------------
* Fix custom_parameters xblock field validation.
Expand Down
2 changes: 1 addition & 1 deletion lti_consumer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
from .apps import LTIConsumerApp
from .lti_xblock import LtiConsumerXBlock

__version__ = '9.8.1'
__version__ = '9.9.0'
23 changes: 20 additions & 3 deletions lti_consumer/lti_xblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock):
"""

block_settings_key = 'lti_consumer'
i18n_js_namespace = 'LtiI18N'

display_name = String(
display_name=_("Display Name"),
Expand Down Expand Up @@ -663,10 +664,13 @@ def workbench_scenarios():
return scenarios

@staticmethod
def _get_statici18n_js_url(loader): # pragma: no cover
def _get_deprecated_i18n_js_url(loader):
"""
Returns the Javascript translation file for the currently selected language, if any found by
Returns the deprecated JavaScript translation file for the currently selected language, if any found by
`pkg_resources`
This method returns pre-OEP-58 i18n files and is deprecated in favor
of `get_javascript_i18n_catalog_url`.
"""
lang_code = translation.get_language()
if not lang_code:
Expand All @@ -678,6 +682,19 @@ def _get_statici18n_js_url(loader): # pragma: no cover
return text_js.format(lang_code=code)
return None

def _get_statici18n_js_url(self, loader):
"""
Return the JavaScript translation file provided by the XBlockI18NService.
"""
if url_getter_func := getattr(self.i18n_service, 'get_javascript_i18n_catalog_url', None):
if javascript_url := url_getter_func(self):
return javascript_url

if deprecated_url := self._get_deprecated_i18n_js_url(loader):
return self.runtime.local_resource_url(self, deprecated_url)

return None

def validate_field_data(self, validation, data):
# Validate custom parameters is a list.
if not isinstance(data.custom_parameters, list):
Expand Down Expand Up @@ -1226,7 +1243,7 @@ def student_view(self, context):
fragment.add_javascript(loader.load_unicode('static/js/xblock_lti_consumer.js'))
statici18n_js_url = self._get_statici18n_js_url(loader)
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

Expand Down

0 comments on commit 78ed4ab

Please sign in to comment.