From 0d691623af54f63067884bbe8157993d5721da5d Mon Sep 17 00:00:00 2001 From: Raul Gallegos Date: Mon, 29 Mar 2021 00:17:44 -0500 Subject: [PATCH] fix: setting correct i18n_service to blockstore runtime xblock information was not being translated correctly when using the blockstore runtime. This makes the i18n_service block-specific so it can look for additional i18n files that can be installed with the XBlock --- .../djangoapps/content_libraries/tests/test_runtime.py | 8 ++++++++ openedx/core/djangoapps/xblock/runtime/runtime.py | 5 ++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/openedx/core/djangoapps/content_libraries/tests/test_runtime.py b/openedx/core/djangoapps/content_libraries/tests/test_runtime.py index dc7aadab27..fa6352d855 100644 --- a/openedx/core/djangoapps/content_libraries/tests/test_runtime.py +++ b/openedx/core/djangoapps/content_libraries/tests/test_runtime.py @@ -2,6 +2,7 @@ Test the Blockstore-based XBlock runtime and content libraries together. """ import json +from gettext import GNUTranslations from completion.test_utils import CompletionWaffleTestMixin from django.db import connections @@ -101,6 +102,13 @@ class ContentLibraryRuntimeTest(ContentLibraryContentTestMixin, TestCase): assert library_api.get_library_block_olx(unit_block_key) == library_api.get_library_block_olx(unit_block2_key) assert unit_block.children != unit_block2.children + def test_dndv2_sets_translator(self): + dnd_block_key = library_api.create_library_block(self.library.key, "drag-and-drop-v2", "dnd1").usage_key + library_api.publish_changes(self.library.key) + dnd_block = xblock_api.load_block(dnd_block_key, self.student_a) + i18n_service = dnd_block.runtime.service(dnd_block, 'i18n') + assert isinstance(i18n_service.translator, GNUTranslations) + def test_has_score(self): """ Test that the LMS-specific 'has_score' attribute is getting added to diff --git a/openedx/core/djangoapps/xblock/runtime/runtime.py b/openedx/core/djangoapps/xblock/runtime/runtime.py index ecfe64adf8..0a38d6db90 100644 --- a/openedx/core/djangoapps/xblock/runtime/runtime.py +++ b/openedx/core/djangoapps/xblock/runtime/runtime.py @@ -78,9 +78,6 @@ class XBlockRuntime(RuntimeShim, Runtime): LmsBlockMixin, # Adds Non-deprecated LMS/Studio functionality XBlockShim, # Adds deprecated LMS/Studio functionality / backwards compatibility ), - services={ - "i18n": ModuleI18nService(), - }, default_class=None, select=None, id_generator=system.id_generator, @@ -229,6 +226,8 @@ class XBlockRuntime(RuntimeShim, Runtime): elif service_name == "completion": context_key = block.scope_ids.usage_id.context_key return CompletionService(user=self.user, context_key=context_key) + elif service_name == "i18n": + return ModuleI18nService(block=block) # Check if the XBlockRuntimeSystem wants to handle this: service = self.system.get_service(block, service_name) # Otherwise, fall back to the base implementation which loads services