Commit 79a0cd24 by Anton Stupak

Merge pull request #3902 from edx/anton/i18n-choice-group

ChoiceGroup  i18n.
parents 9cc5cf0e 71b90a91
...@@ -433,6 +433,7 @@ class ChoiceGroup(InputTypeBase): ...@@ -433,6 +433,7 @@ class ChoiceGroup(InputTypeBase):
tags = ['choicegroup', 'radiogroup', 'checkboxgroup'] tags = ['choicegroup', 'radiogroup', 'checkboxgroup']
def setup(self): def setup(self):
i18n = self.capa_system.i18n
# suffix is '' or [] to change the way the input is handled in --as a scalar or vector # suffix is '' or [] to change the way the input is handled in --as a scalar or vector
# value. (VS: would be nice to make this less hackish). # value. (VS: would be nice to make this less hackish).
if self.tag == 'choicegroup': if self.tag == 'choicegroup':
...@@ -445,16 +446,20 @@ class ChoiceGroup(InputTypeBase): ...@@ -445,16 +446,20 @@ class ChoiceGroup(InputTypeBase):
self.html_input_type = "checkbox" self.html_input_type = "checkbox"
self.suffix = '[]' self.suffix = '[]'
else: else:
raise Exception("ChoiceGroup: unexpected tag {0}".format(self.tag)) _ = i18n.ugettext
# Translators: 'ChoiceGroup' is an input type and should not be translated.
msg = _("ChoiceGroup: unexpected tag {tag_name}").format(tag_name=self.tag)
raise Exception(msg)
self.choices = self.extract_choices(self.xml) self.choices = self.extract_choices(self.xml, i18n)
self._choices_map = dict(self.choices) # pylint: disable=attribute-defined-outside-init self._choices_map = dict(self.choices,) # pylint: disable=attribute-defined-outside-init
@classmethod @classmethod
def get_attributes(cls): def get_attributes(cls):
_ = lambda text: text
return [Attribute("show_correctness", "always"), return [Attribute("show_correctness", "always"),
Attribute('label', ''), Attribute('label', ''),
Attribute("submitted_message", "Answer received.")] Attribute("submitted_message", _("Answer received."))]
def _extra_context(self): def _extra_context(self):
return {'input_type': self.html_input_type, return {'input_type': self.html_input_type,
...@@ -462,7 +467,7 @@ class ChoiceGroup(InputTypeBase): ...@@ -462,7 +467,7 @@ class ChoiceGroup(InputTypeBase):
'name_array_suffix': self.suffix} 'name_array_suffix': self.suffix}
@staticmethod @staticmethod
def extract_choices(element): def extract_choices(element, i18n):
""" """
Extracts choices for a few input types, such as ChoiceGroup, RadioGroup and Extracts choices for a few input types, such as ChoiceGroup, RadioGroup and
CheckboxGroup. CheckboxGroup.
...@@ -474,12 +479,17 @@ class ChoiceGroup(InputTypeBase): ...@@ -474,12 +479,17 @@ class ChoiceGroup(InputTypeBase):
""" """
choices = [] choices = []
_ = i18n.ugettext
for choice in element: for choice in element:
if choice.tag != 'choice': if choice.tag != 'choice':
raise Exception( msg = u"[capa.inputtypes.extract_choices] {error_message}".format(
"[capa.inputtypes.extract_choices] Expected a <choice> tag; got %s instead" # Translators: '<choice>' is a tag name and should not be translated.
% choice.tag) error_message=_("Expected a <choice> tag; got {given_tag} instead").format(
given_tag=choice.tag
)
)
raise Exception(msg)
choices.append((choice.get("name"), stringify_children(choice))) choices.append((choice.get("name"), stringify_children(choice)))
return choices return choices
......
<%! from django.utils.translation import ugettext as _ %>
<% element_checked = False %> <% element_checked = False %>
% for choice_id, _ in choices: % for choice_id, _ in choices:
<%choice_id = choice_id %> <%choice_id = choice_id %>
...@@ -62,7 +63,7 @@ ...@@ -62,7 +63,7 @@
</fieldset> </fieldset>
<input class= "choicetextvalue" type="hidden" name="input_${id}{}" id="input_${id}" value="${value|h}" /> <input class= "choicetextvalue" type="hidden" name="input_${id}{}" id="input_${id}" value="${value|h}" />
% if show_correctness == "never" and (value or status not in ['unsubmitted']): % if show_correctness == "never" and (value or status not in ['unsubmitted']):
<div class="capa_alert">${submitted_message}</div> <div class="capa_alert">${_(submitted_message)}</div>
%endif %endif
% if msg: % if msg:
<span class="message">${msg|n}</span> <span class="message">${msg|n}</span>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment