Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #12230 - Updated utils.translation.to_locale to support the spe…

…cial sr_Latn locale. Thanks to Janos Guljas.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12056 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 855e805b4cd1ce40751ef166d36cc6f0ae2a2519 1 parent 18c31f6
@jezdez jezdez authored
View
3  django/utils/translation/trans_real.py
@@ -41,6 +41,9 @@ def to_locale(language, to_lower=False):
if to_lower:
return language[:p].lower()+'_'+language[p+1:].lower()
else:
+ # Get correct locale for sr-latn
+ if len(language[p+1:]) > 2:
+ return language[:p].lower()+'_'+language[p+1].upper()+language[p+2:].lower()
return language[:p].lower()+'_'+language[p+1:].upper()
else:
return language.lower()
View
19 tests/regressiontests/i18n/tests.py
@@ -7,7 +7,7 @@
from django.utils.formats import get_format, date_format, time_format, number_format, localize, localize_input
from django.utils.numberformat import format
from django.test import TestCase, client
-from django.utils.translation import ugettext, ugettext_lazy, activate, deactivate, gettext_lazy
+from django.utils.translation import ugettext, ugettext_lazy, activate, deactivate, gettext_lazy, to_locale
from forms import I18nForm, SelectDateForm, SelectDateWidget, CompanyForm
@@ -81,6 +81,23 @@ def test_maclines(self):
finally:
deactivate()
+ def test_to_locale(self):
+ """
+ Tests the to_locale function and the special case of Serbian Latin
+ (refs #12230 and r11299)
+ """
+ self.assertEqual(to_locale('en-us'), 'en_US')
+ self.assertEqual(to_locale('sr-lat'), 'sr_Lat')
+
+ def test_to_language(self):
+ """
+ Test the to_language function
+ """
+ from django.utils.translation.trans_real import to_language
+ self.assertEqual(to_language('en_US'), 'en-us')
+ self.assertEqual(to_language('sr_Lat'), 'sr-lat')
+
+
class FormattingTests(TestCase):
def setUp(self):
Please sign in to comment.
Something went wrong with that request. Please try again.