From 32a7b9f604b900df53382f84214c86ab881e65ca Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Mon, 3 Dec 2018 19:32:43 -0500 Subject: [PATCH] Use XBlock services to get translation at runtime --- common/lib/xmodule/xmodule/seq_module.py | 5 +++++ common/lib/xmodule/xmodule/tests/test_sequence.py | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/common/lib/xmodule/xmodule/seq_module.py b/common/lib/xmodule/xmodule/seq_module.py index d8e821c699..2d0f420f91 100644 --- a/common/lib/xmodule/xmodule/seq_module.py +++ b/common/lib/xmodule/xmodule/seq_module.py @@ -165,6 +165,7 @@ class ProctoringFields(object): @XBlock.wants('completion') @XBlock.needs('user') @XBlock.needs('bookmarks') +@XBlock.needs('i18n') class SequenceModule(SequenceFields, ProctoringFields, XModule): """ Layout module which lays out content in a temporal sequence @@ -238,6 +239,7 @@ class SequenceModule(SequenceFields, ProctoringFields, XModule): ) def student_view(self, context): + _ = self.runtime.service(self, "i18n").ugettext context = context or {} self._capture_basic_metrics() banner_text = None @@ -265,6 +267,7 @@ class SequenceModule(SequenceFields, ProctoringFields, XModule): a banner_text or the fragment to display depending on whether staff is masquerading. """ + _ = self.runtime.service(self, "i18n").ugettext if self.is_time_limited: special_exam_html = self._time_limited_student_view() if special_exam_html: @@ -277,6 +280,7 @@ class SequenceModule(SequenceFields, ProctoringFields, XModule): runtime user. If so, returns a banner_text or the fragment to display depending on whether staff is masquerading. """ + _ = self.runtime.service(self, "i18n").ugettext course = self._get_course() if not self._can_user_view_content(course): if course.self_paced: @@ -315,6 +319,7 @@ class SequenceModule(SequenceFields, ProctoringFields, XModule): sequential. If banner_text is given, it is added to the content. """ + _ = self.runtime.service(self, "i18n").ugettext display_items = self.get_display_items() self._update_position(context, len(display_items)) diff --git a/common/lib/xmodule/xmodule/tests/test_sequence.py b/common/lib/xmodule/xmodule/tests/test_sequence.py index ea739e731d..a52e239449 100644 --- a/common/lib/xmodule/xmodule/tests/test_sequence.py +++ b/common/lib/xmodule/xmodule/tests/test_sequence.py @@ -166,7 +166,7 @@ class SequenceBlockTestCase(XModuleXmlImportTest): ) self.assertIn("seq_module.html", html) self.assertIn( - "'banner_text': 'Because the due date has passed, " + "'banner_text': u'Because the due date has passed, " "this assignment is hidden from the learner.'", html ) @@ -208,7 +208,7 @@ class SequenceBlockTestCase(XModuleXmlImportTest): """ self.assertIn("seq_module.html", html) self.assertIn( - "'banner_text': 'This section is a prerequisite. " + "'banner_text': u'This section is a prerequisite. " "You must complete this section in order to unlock additional content.'", html )