mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
[4.1.x] Fixed #23689 -- Made parsing HTTP Accept-Language header case-insensitive.
Thank you Daniel Samuels for test project.
Backport of 901a169198 from main
This commit is contained in:
committed by
Mariusz Felisiak
parent
5197014eff
commit
f741dd5fab
@@ -61,7 +61,7 @@ def get_language_from_path(request):
|
||||
|
||||
|
||||
def get_supported_language_variant(lang_code, strict=False):
|
||||
if lang_code == settings.LANGUAGE_CODE:
|
||||
if lang_code and lang_code.lower() == settings.LANGUAGE_CODE.lower():
|
||||
return lang_code
|
||||
else:
|
||||
raise LookupError(lang_code)
|
||||
|
||||
@@ -478,8 +478,9 @@ def check_for_language(lang_code):
|
||||
def get_languages():
|
||||
"""
|
||||
Cache of settings.LANGUAGES in a dictionary for easy lookups by key.
|
||||
Convert keys to lowercase as they should be treated as case-insensitive.
|
||||
"""
|
||||
return dict(settings.LANGUAGES)
|
||||
return {key.lower(): value for key, value in dict(settings.LANGUAGES).items()}
|
||||
|
||||
|
||||
@functools.lru_cache(maxsize=1000)
|
||||
@@ -510,7 +511,7 @@ def get_supported_language_variant(lang_code, strict=False):
|
||||
supported_lang_codes = get_languages()
|
||||
|
||||
for code in possible_lang_codes:
|
||||
if code in supported_lang_codes and check_for_language(code):
|
||||
if code.lower() in supported_lang_codes and check_for_language(code):
|
||||
return code
|
||||
if not strict:
|
||||
# if fr-fr is not supported, try fr-ca.
|
||||
|
||||
Reference in New Issue
Block a user