mirror of
https://github.com/django/django.git
synced 2024-12-24 18:16:19 +00:00
Fixed #14461 -- Look also in LOCALE_PATHS when checking if a language is supported. Thanks to Diego Búrigo for the initial patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15507 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
204e83e331
commit
e1e3f24371
@ -335,19 +335,26 @@ def npgettext(context, singular, plural, number):
|
|||||||
result = do_ntranslate(singular, plural, number, 'ungettext')
|
result = do_ntranslate(singular, plural, number, 'ungettext')
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def all_locale_paths():
|
||||||
|
"""
|
||||||
|
Returns a list of paths to user-provides languages files.
|
||||||
|
"""
|
||||||
|
from django.conf import settings
|
||||||
|
globalpath = os.path.join(
|
||||||
|
os.path.dirname(sys.modules[settings.__module__].__file__), 'locale')
|
||||||
|
return [globalpath] + list(settings.LOCALE_PATHS)
|
||||||
|
|
||||||
def check_for_language(lang_code):
|
def check_for_language(lang_code):
|
||||||
"""
|
"""
|
||||||
Checks whether there is a global language file for the given language
|
Checks whether there is a global language file for the given language
|
||||||
code. This is used to decide whether a user-provided language is
|
code. This is used to decide whether a user-provided language is
|
||||||
available. This is only used for language codes from either the cookies or
|
available. This is only used for language codes from either the cookies or
|
||||||
session.
|
session and during format localization.
|
||||||
"""
|
"""
|
||||||
from django.conf import settings
|
for path in all_locale_paths():
|
||||||
globalpath = os.path.join(os.path.dirname(sys.modules[settings.__module__].__file__), 'locale')
|
if gettext_module.find('django', path, [to_locale(lang_code)]) is not None:
|
||||||
if gettext_module.find('django', globalpath, [to_locale(lang_code)]) is not None:
|
return True
|
||||||
return True
|
return False
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
def get_language_from_request(request):
|
def get_language_from_request(request):
|
||||||
"""
|
"""
|
||||||
@ -358,7 +365,8 @@ def get_language_from_request(request):
|
|||||||
"""
|
"""
|
||||||
global _accepted
|
global _accepted
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
globalpath = os.path.join(os.path.dirname(sys.modules[settings.__module__].__file__), 'locale')
|
globalpath = os.path.join(
|
||||||
|
os.path.dirname(sys.modules[settings.__module__].__file__), 'locale')
|
||||||
supported = dict(settings.LANGUAGES)
|
supported = dict(settings.LANGUAGES)
|
||||||
|
|
||||||
if hasattr(request, 'session'):
|
if hasattr(request, 'session'):
|
||||||
@ -401,11 +409,10 @@ def get_language_from_request(request):
|
|||||||
(accept_lang.split('-')[0], normalized.split('_')[0])):
|
(accept_lang.split('-')[0], normalized.split('_')[0])):
|
||||||
if lang.lower() not in supported:
|
if lang.lower() not in supported:
|
||||||
continue
|
continue
|
||||||
langfile = os.path.join(globalpath, dirname, 'LC_MESSAGES',
|
for path in all_locale_paths():
|
||||||
'django.mo')
|
if os.path.exists(os.path.join(path, dirname, 'LC_MESSAGES', 'django.mo')):
|
||||||
if os.path.exists(langfile):
|
_accepted[normalized] = lang
|
||||||
_accepted[normalized] = lang
|
return lang
|
||||||
return lang
|
|
||||||
|
|
||||||
return settings.LANGUAGE_CODE
|
return settings.LANGUAGE_CODE
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user