From 10bd6754b1db74efb10b11c03169c5f8f246e79e Mon Sep 17 00:00:00 2001 From: Saqib Date: Wed, 24 Jun 2020 10:52:31 +0500 Subject: [PATCH] MCKIN-19683: fix translations issues (#288) * fix translations issues * korean translation update --- problem_builder/answer.py | 15 +++++++++++--- problem_builder/questionnaire.py | 19 +++++++++++++++++- .../translations/ko_KR/LC_MESSAGES/text.mo | Bin 37628 -> 37619 bytes .../translations/ko_KR/LC_MESSAGES/text.po | 8 ++++---- setup.py | 2 +- 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/problem_builder/answer.py b/problem_builder/answer.py index 48737a4b..faaadcd4 100644 --- a/problem_builder/answer.py +++ b/problem_builder/answer.py @@ -40,6 +40,7 @@ StudentViewUserStateMixin, XBlockWithTranslationServiceMixin) from .models import Answer +from .utils import I18NService # Globals ########################################################### @@ -54,7 +55,7 @@ def _(text): # Classes ########################################################### -class AnswerMixin(XBlockWithPreviewMixin, XBlockWithTranslationServiceMixin, StudentViewUserStateMixin): +class AnswerMixin(XBlockWithPreviewMixin, XBlockWithTranslationServiceMixin, StudentViewUserStateMixin, I18NService): """ Mixin to give an XBlock the ability to read/write data to the Answers DB table. """ @@ -200,7 +201,11 @@ def mentoring_view(self, context=None): context['answer_editable_id'] = uuid.uuid4().hex[:15] context['self'] = self context['hide_header'] = context.get('hide_header', False) or not self.show_title - html = loader.render_django_template('templates/html/answer_editable.html', context) + html = loader.render_django_template( + 'templates/html/answer_editable.html', + context, + i18n_service=self.i18n_service + ) fragment = Fragment(html) fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/answer.css')) @@ -349,7 +354,11 @@ def mentoring_view(self, context=None): context['student_input'] = None else: context['student_input'] = self.student_input - html = loader.render_django_template('templates/html/answer_read_only.html', context) + html = loader.render_django_template( + 'templates/html/answer_read_only.html', + context, + i18n_service=self.i18n_service + ) fragment = Fragment(html) fragment.add_css_url(self.runtime.local_resource_url(self, self.css_path)) diff --git a/problem_builder/questionnaire.py b/problem_builder/questionnaire.py index aa255888..41fbc210 100644 --- a/problem_builder/questionnaire.py +++ b/problem_builder/questionnaire.py @@ -20,8 +20,10 @@ # Imports ########################################################### +import pkg_resources import uuid +from django import utils from django.utils.safestring import mark_safe from lazy import lazy from xblock.core import XBlock @@ -85,6 +87,20 @@ def html_id(self): """ return uuid.uuid4().hex[:20] + @staticmethod + def resource_string(path): + """Handy helper for getting resources from our kit.""" + data = pkg_resources.resource_string(__name__, path) + return data.decode("utf8") + + def get_translation_content(self): + try: + return self.resource_string('public/js/translations/{lang}/textjs.js'.format( + lang=utils.translation.to_locale(utils.translation.get_language()), + )) + except IOError: + return self.resource_string('public/js/translations/en/textjs.js') + def student_view(self, context=None): name = getattr(self, "unmixed_class", self.__class__).__name__ @@ -95,7 +111,7 @@ def student_view(self, context=None): context['custom_choices'] = self.custom_choices context['hide_header'] = context.get('hide_header', False) or not self.show_title - fragment = Fragment(loader.render_django_template(template_path, context)) + fragment = Fragment(loader.render_django_template(template_path, context, i18n_service=self.i18n_service)) # If we use local_resource_url(self, ...) the runtime may insert many identical copies # of questionnaire.[css/js] into the DOM. So we use the mentoring block here if possible. block_with_resources = self.get_parent() @@ -105,6 +121,7 @@ def student_view(self, context=None): block_with_resources = self fragment.add_css_url(self.runtime.local_resource_url(block_with_resources, 'public/css/questionnaire.css')) fragment.add_javascript_url(self.runtime.local_resource_url(block_with_resources, 'public/js/questionnaire.js')) + fragment.add_javascript(self.get_translation_content()) fragment.initialize_js(name) return fragment diff --git a/problem_builder/translations/ko_KR/LC_MESSAGES/text.mo b/problem_builder/translations/ko_KR/LC_MESSAGES/text.mo index 1f1797adfc05d363a4d8a5226f5c677859a58698..58bee51ccfca1b8b7808dd16228a3e8d7b04cf6a 100644 GIT binary patch delta 2952 zcmXZddra0<7{KudP}Ele$qT5{5L8eDOhqn2i7pwY+(ZFEgRnGRsZWT2XB#T2iJ<*G0C*EaxS+64v+OoIhSZ=Q+RgJLfsKA5WUSA2fTn zJao9jyhH|PiZqExbe71c*nv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