55
55
import urllib .parse
56
56
from collections import namedtuple
57
57
from importlib import import_module
58
- import pkg_resources
59
58
60
59
import bleach
61
60
from django .conf import settings
62
- from django .utils import timezone , translation
61
+ from django .utils import timezone
63
62
from web_fragments .fragment import Fragment
64
63
65
64
from webob import Response
@@ -257,6 +256,7 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock):
257
256
"""
258
257
259
258
block_settings_key = 'lti_consumer'
259
+ i18n_js_namespace = 'XBlockLtiConsumerI18N'
260
260
261
261
display_name = String (
262
262
display_name = _ ("Display Name" ),
@@ -662,20 +662,15 @@ def workbench_scenarios():
662
662
]
663
663
return scenarios
664
664
665
- @staticmethod
666
- def _get_statici18n_js_url (loader ): # pragma: no cover
667
- """
668
- Returns the Javascript translation file for the currently selected language, if any found by
669
- `pkg_resources`
670
- """
671
- lang_code = translation .get_language ()
672
- if not lang_code :
673
- return None
674
- text_js = 'public/js/translations/{lang_code}/text.js'
675
- country_code = lang_code .split ('-' )[0 ]
676
- for code in (translation .to_locale (lang_code ), lang_code , country_code ):
677
- if pkg_resources .resource_exists (loader .module_name , text_js .format (lang_code = code )):
678
- return text_js .format (lang_code = code )
665
+ def _get_statici18n_js_url (self ):
666
+ """
667
+ Return the JavaScript translation file provided by the XBlockI18NService.
668
+ """
669
+ if i18n_service := self .runtime .service (self , 'i18n' ):
670
+ if url_getter_func := getattr (i18n_service , 'get_javascript_i18n_catalog_url' , None ):
671
+ if javascript_url := url_getter_func (self ):
672
+ return javascript_url
673
+
679
674
return None
680
675
681
676
def validate_field_data (self , validation , data ):
@@ -1197,9 +1192,9 @@ def author_view(self, context):
1197
1192
)
1198
1193
fragment .add_css (loader .load_unicode ('static/css/student.css' ))
1199
1194
fragment .add_javascript (loader .load_unicode ('static/js/xblock_lti_consumer.js' ))
1200
- statici18n_js_url = self ._get_statici18n_js_url (loader )
1195
+ statici18n_js_url = self ._get_statici18n_js_url ()
1201
1196
if statici18n_js_url :
1202
- fragment .add_javascript_url (self . runtime . local_resource_url ( self , statici18n_js_url ) )
1197
+ fragment .add_javascript_url (statici18n_js_url )
1203
1198
fragment .initialize_js ('LtiConsumerXBlock' )
1204
1199
return fragment
1205
1200
@@ -1224,9 +1219,9 @@ def student_view(self, context):
1224
1219
fragment .add_content (loader .render_mako_template ('/templates/html/student.html' , context ))
1225
1220
fragment .add_css (loader .load_unicode ('static/css/student.css' ))
1226
1221
fragment .add_javascript (loader .load_unicode ('static/js/xblock_lti_consumer.js' ))
1227
- statici18n_js_url = self ._get_statici18n_js_url (loader )
1222
+ statici18n_js_url = self ._get_statici18n_js_url ()
1228
1223
if statici18n_js_url :
1229
- fragment .add_javascript_url (self . runtime . local_resource_url ( self , statici18n_js_url ) )
1224
+ fragment .add_javascript_url (statici18n_js_url )
1230
1225
fragment .initialize_js ('LtiConsumerXBlock' )
1231
1226
return fragment
1232
1227
0 commit comments