summaryrefslogtreecommitdiff
path: root/django/utils
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2021-03-21 19:03:57 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-03-22 07:08:58 +0100
commitd11b9ffcc0b1d6b8e87df6319f09bf284196e41a (patch)
tree612d11b9b37bcd7084e368e420abad9142a6d0f3 /django/utils
parent9d130920e61570d1e8dfd8ee174bc5d86771f054 (diff)
Fixed #32581 -- Prevented to_locale() from corrupting locale names.
Diffstat (limited to 'django/utils')
-rw-r--r--django/utils/translation/__init__.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/django/utils/translation/__init__.py b/django/utils/translation/__init__.py
index aa5cd33f5b..29ac60ad1d 100644
--- a/django/utils/translation/__init__.py
+++ b/django/utils/translation/__init__.py
@@ -201,9 +201,9 @@ def to_language(locale):
def to_locale(language):
"""Turn a language name (en-us) into a locale name (en_US)."""
- language, _, country = language.lower().partition('-')
+ lang, _, country = language.lower().partition('-')
if not country:
- return language
+ return language[:3].lower() + language[3:]
# A language with > 2 characters after the dash only has its first
# character after the dash capitalized; e.g. sr-latn becomes sr_Latn.
# A language with 2 characters after the dash has both characters
@@ -212,7 +212,7 @@ def to_locale(language):
country = country.title() if len(country) > 2 else country.upper()
if tail:
country += '-' + tail
- return language + '_' + country
+ return lang + '_' + country
def get_language_from_request(request, check_path=False):