@@ -80,6 +80,8 @@ class DragAndDropBlock(
80
80
SOLUTION_INCORRECT : None
81
81
}
82
82
83
+ i18n_js_namespace = 'DragAndDropI18N'
84
+
83
85
display_name = String (
84
86
display_name = _ ("Title" ),
85
87
help = _ ("The title of the drag and drop problem. The title is displayed to learners." ),
@@ -319,11 +321,13 @@ def _learner_raw_score(self):
319
321
correct_count , total_count = self ._get_item_stats ()
320
322
return correct_count / float (total_count )
321
323
322
- @staticmethod
323
- def _get_statici18n_js_url ():
324
+ def _get_deprecated_i18n_js_url (self ):
324
325
"""
325
- Returns the Javascript translation file for the currently selected language, if any found by
326
+ Returns the deprecated JavaScript translation file for the currently selected language, if any found by
326
327
`pkg_resources`
328
+
329
+ This method returns pre-OEP-58 i18n files and is deprecated in favor
330
+ of `get_javascript_i18n_catalog_url`.
327
331
"""
328
332
lang_code = translation .get_language ()
329
333
if not lang_code :
@@ -335,6 +339,19 @@ def _get_statici18n_js_url():
335
339
return text_js .format (lang_code = code )
336
340
return None
337
341
342
+ def _get_statici18n_js_url (self ):
343
+ """
344
+ Return the JavaScript translation file provided by the XBlockI18NService.
345
+ """
346
+ if url_getter_func := getattr (self .i18n_service , 'get_javascript_i18n_catalog_url' , None ):
347
+ if javascript_url := url_getter_func (self ):
348
+ return javascript_url
349
+
350
+ if deprecated_url := self ._get_deprecated_i18n_js_url ():
351
+ return self .runtime .local_resource_url (self , deprecated_url )
352
+
353
+ return None
354
+
338
355
@XBlock .supports ("multi_device" ) # Enable this block for use in the mobile app via webview
339
356
def student_view (self , context ):
340
357
"""
@@ -352,15 +369,15 @@ def student_view(self, context):
352
369
'public/js/drag_and_drop.js' ,
353
370
]
354
371
355
- statici18n_js_url = self ._get_statici18n_js_url ()
356
- if statici18n_js_url :
357
- js_urls .append (statici18n_js_url )
358
-
359
372
for css_url in css_urls :
360
373
fragment .add_css_url (self .runtime .local_resource_url (self , css_url ))
361
374
for js_url in js_urls :
362
375
fragment .add_javascript_url (self .runtime .local_resource_url (self , js_url ))
363
376
377
+ statici18n_js_url = self ._get_statici18n_js_url ()
378
+ if statici18n_js_url :
379
+ fragment .add_javascript_url (statici18n_js_url )
380
+
364
381
self .include_theme_files (fragment )
365
382
366
383
fragment .initialize_js ('DragAndDropBlock' , self .student_view_data ())
@@ -458,15 +475,15 @@ def studio_view(self, context):
458
475
'public/js/drag_and_drop_edit.js' ,
459
476
]
460
477
461
- statici18n_js_url = self ._get_statici18n_js_url ()
462
- if statici18n_js_url :
463
- js_urls .append (statici18n_js_url )
464
-
465
478
for css_url in css_urls :
466
479
fragment .add_css_url (self .runtime .local_resource_url (self , css_url ))
467
480
for js_url in js_urls :
468
481
fragment .add_javascript_url (self .runtime .local_resource_url (self , js_url ))
469
482
483
+ statici18n_js_url = self ._get_statici18n_js_url ()
484
+ if statici18n_js_url :
485
+ fragment .add_javascript_url (statici18n_js_url )
486
+
470
487
# Do a bit of manipulation so we get the appearance of a list of zone options on
471
488
# items that still have just a single zone stored
472
489
0 commit comments