diff --git a/openstack_dashboard/dashboards/settings/user/forms.py b/openstack_dashboard/dashboards/settings/user/forms.py index 759859bf51..6ba67b5dbe 100644 --- a/openstack_dashboard/dashboards/settings/user/forms.py +++ b/openstack_dashboard/dashboards/settings/user/forms.py @@ -48,9 +48,16 @@ class UserSettingsForm(forms.SelfHandlingForm): super(UserSettingsForm, self).__init__(*args, **kwargs) # Languages - languages = [(k, "%s (%s)" - % (translation.get_language_info(k)['name_local'], k)) - for k, v in settings.LANGUAGES] + def get_language_display_name(code, desc): + try: + desc = translation.get_language_info(code)['name_local'] + except KeyError: + # If a language is not defined in django.conf.locale.LANG_INFO + # get_language_info raises KeyError + pass + return "%s (%s)" % (desc, code) + languages = [(k, get_language_display_name(k, v)) + for k, v in settings.LANGUAGES] self.fields['language'].choices = languages # Timezones diff --git a/openstack_dashboard/dashboards/settings/user/tests.py b/openstack_dashboard/dashboards/settings/user/tests.py index bfa6f36ad2..ee3355f11f 100644 --- a/openstack_dashboard/dashboards/settings/user/tests.py +++ b/openstack_dashboard/dashboards/settings/user/tests.py @@ -14,6 +14,7 @@ # License for the specific language governing permissions and limitations # under the License. +from django.conf import settings # noqa from django.core.urlresolvers import reverse # noqa from openstack_dashboard.test import helpers as test @@ -31,3 +32,13 @@ class UserSettingsTest(test.TestCase): self.assertContains(res, "Europe/Moscow (UTC +04:00)") self.assertContains(res, "Atlantic/Stanley (UTC -03:00)") self.assertContains(res, "Pacific/Honolulu (UTC -10:00)") + + def test_display_language(self): + # Add an unknown language to LANGUAGES list + settings.LANGUAGES += (('unknown', 'Unknown Language'),) + + res = self.client.get(INDEX_URL) + # Known language + self.assertContains(res, 'English') + # Unknown language + self.assertContains(res, 'Unknown Language')