BLD-726: ChoiceTextGroup i18n.
This commit is contained in:
@@ -1661,23 +1661,28 @@ class ChoiceTextGroup(InputTypeBase):
|
||||
elif self.tag == 'checkboxtextgroup':
|
||||
self.html_input_type = "checkbox"
|
||||
else:
|
||||
raise Exception("ChoiceGroup: unexpected tag {0}".format(self.tag))
|
||||
_ = self.capa_system.i18n.ugettext
|
||||
msg = _("{input_type}: unexpected tag {tag_name}").format(
|
||||
input_type="ChoiceTextGroup", tag_name=self.tag
|
||||
)
|
||||
raise Exception(msg)
|
||||
|
||||
if self.value == '':
|
||||
# Make `value` an empty dictionary, if it currently has an empty
|
||||
# value. This is necessary because the template expects a
|
||||
# dictionary.
|
||||
self.value = {}
|
||||
self.choices = self.extract_choices(self.xml)
|
||||
self.choices = self.extract_choices(self.xml, self.capa_system.i18n)
|
||||
|
||||
@classmethod
|
||||
def get_attributes(cls):
|
||||
"""
|
||||
Returns a list of `Attribute` for this problem type
|
||||
"""
|
||||
_ = lambda text: text
|
||||
return [
|
||||
Attribute("show_correctness", "always"),
|
||||
Attribute("submitted_message", "Answer received."),
|
||||
Attribute("submitted_message", _("Answer received.")),
|
||||
Attribute("label", ""),
|
||||
]
|
||||
|
||||
@@ -1694,7 +1699,7 @@ class ChoiceTextGroup(InputTypeBase):
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def extract_choices(element):
|
||||
def extract_choices(element, i18n):
|
||||
"""
|
||||
Extracts choices from the xml for this problem type.
|
||||
If we have xml that is as follows(choice names will have been assigned
|
||||
@@ -1734,14 +1739,19 @@ class ChoiceTextGroup(InputTypeBase):
|
||||
]
|
||||
"""
|
||||
|
||||
_ = i18n.ugettext
|
||||
choices = []
|
||||
|
||||
for choice in element:
|
||||
if choice.tag != 'choice':
|
||||
raise Exception(
|
||||
"[capa.inputtypes.extract_choices] Expected a <choice>" +
|
||||
"tag; got {0} instead".format(choice.tag)
|
||||
msg = "[capa.inputtypes.extract_choices] {0}".format(
|
||||
# Translators: a "tag" is an XML element, such as "<b>" in HTML
|
||||
_("Expected a {expected_tag} tag; got {given_tag} instead").format(
|
||||
expected_tag=u"<choice>",
|
||||
given_tag=choice.tag,
|
||||
)
|
||||
)
|
||||
raise Exception(msg)
|
||||
|
||||
components = []
|
||||
choice_text = ''
|
||||
|
||||
Reference in New Issue
Block a user