Commit 58e92b52 by Matjaz Gregoric

LOC-73: Translate education/gender options in registration form.

The education level and gender choices weren't being translated for
display on the combined login/registration form.
parent d26d03da
...@@ -999,6 +999,32 @@ class RegistrationViewTest(ThirdPartyAuthTestMixin, ApiTestCase): ...@@ -999,6 +999,32 @@ class RegistrationViewTest(ThirdPartyAuthTestMixin, ApiTestCase):
} }
) )
@mock.patch('openedx.core.djangoapps.user_api.views._')
def test_register_form_level_of_education_translations(self, fake_gettext):
fake_gettext.side_effect = lambda text: text + ' TRANSLATED'
self._assert_reg_field(
{"level_of_education": "optional"},
{
"name": "level_of_education",
"type": "select",
"required": False,
"label": "Highest level of education completed TRANSLATED",
"options": [
{"value": "", "name": "--", "default": True},
{"value": "p", "name": "Doctorate TRANSLATED"},
{"value": "m", "name": "Master's or professional degree TRANSLATED"},
{"value": "b", "name": "Bachelor's degree TRANSLATED"},
{"value": "a", "name": "Associate degree TRANSLATED"},
{"value": "hs", "name": "Secondary/high school TRANSLATED"},
{"value": "jhs", "name": "Junior secondary/junior high/middle school TRANSLATED"},
{"value": "el", "name": "Elementary/primary school TRANSLATED"},
{"value": "none", "name": "None TRANSLATED"},
{"value": "other", "name": "Other TRANSLATED"},
],
}
)
def test_register_form_gender(self): def test_register_form_gender(self):
self._assert_reg_field( self._assert_reg_field(
{"gender": "optional"}, {"gender": "optional"},
...@@ -1016,6 +1042,26 @@ class RegistrationViewTest(ThirdPartyAuthTestMixin, ApiTestCase): ...@@ -1016,6 +1042,26 @@ class RegistrationViewTest(ThirdPartyAuthTestMixin, ApiTestCase):
} }
) )
@mock.patch('openedx.core.djangoapps.user_api.views._')
def test_register_form_gender_translations(self, fake_gettext):
fake_gettext.side_effect = lambda text: text + ' TRANSLATED'
self._assert_reg_field(
{"gender": "optional"},
{
"name": "gender",
"type": "select",
"required": False,
"label": "Gender TRANSLATED",
"options": [
{"value": "", "name": "--", "default": True},
{"value": "m", "name": "Male TRANSLATED"},
{"value": "f", "name": "Female TRANSLATED"},
{"value": "o", "name": "Other TRANSLATED"},
],
}
)
def test_register_form_year_of_birth(self): def test_register_form_year_of_birth(self):
this_year = datetime.datetime.now(UTC).year this_year = datetime.datetime.now(UTC).year
year_options = ( year_options = (
......
...@@ -449,11 +449,13 @@ class RegistrationView(APIView): ...@@ -449,11 +449,13 @@ class RegistrationView(APIView):
# form used to select the user's highest completed level of education. # form used to select the user's highest completed level of education.
education_level_label = _(u"Highest level of education completed") education_level_label = _(u"Highest level of education completed")
# The labels are marked for translation in UserProfile model definition.
options = [(name, _(label)) for name, label in UserProfile.LEVEL_OF_EDUCATION_CHOICES] # pylint: disable=translation-of-non-string
form_desc.add_field( form_desc.add_field(
"level_of_education", "level_of_education",
label=education_level_label, label=education_level_label,
field_type="select", field_type="select",
options=UserProfile.LEVEL_OF_EDUCATION_CHOICES, options=options,
include_default_option=True, include_default_option=True,
required=required required=required
) )
...@@ -472,11 +474,13 @@ class RegistrationView(APIView): ...@@ -472,11 +474,13 @@ class RegistrationView(APIView):
# form used to select the user's gender. # form used to select the user's gender.
gender_label = _(u"Gender") gender_label = _(u"Gender")
# The labels are marked for translation in UserProfile model definition.
options = [(name, _(label)) for name, label in UserProfile.GENDER_CHOICES] # pylint: disable=translation-of-non-string
form_desc.add_field( form_desc.add_field(
"gender", "gender",
label=gender_label, label=gender_label,
field_type="select", field_type="select",
options=UserProfile.GENDER_CHOICES, options=options,
include_default_option=True, include_default_option=True,
required=required required=required
) )
......
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