From 0e2bf2234dff13eddc63af61db24414d71083ba5 Mon Sep 17 00:00:00 2001 From: polesye Date: Wed, 11 Jun 2014 13:34:52 +0300 Subject: [PATCH] BLD-726: ChoiceTextGroup i18n. --- common/lib/capa/capa/inputtypes.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/common/lib/capa/capa/inputtypes.py b/common/lib/capa/capa/inputtypes.py index 0b6a27fd3f..bbae259403 100644 --- a/common/lib/capa/capa/inputtypes.py +++ b/common/lib/capa/capa/inputtypes.py @@ -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 " + - "tag; got {0} instead".format(choice.tag) + msg = "[capa.inputtypes.extract_choices] {0}".format( + # Translators: a "tag" is an XML element, such as "" in HTML + _("Expected a {expected_tag} tag; got {given_tag} instead").format( + expected_tag=u"", + given_tag=choice.tag, + ) ) + raise Exception(msg) components = [] choice_text = ''