I want to make internationalization for my project. I followed how it is described in official documentation, but localization still doesn't work. Here is how I try get user locale:
def get_locale_name(request):
""" Return the :term:`locale name` associated with the current
request (possibly cached)."""
locale_name = getattr(request, 'locale_name', None)
if locale_name is None:
locale_name = negotiate_locale_name(request)
request.locale_name = locale_name
return locale_name
But request
doesn't have attr "local_name", but it has "Accept-Language" and so when function get_local_name
doesn't find "local_name" in the request, it calls another function:
def negotiate_locale_name(request):
""" Negotiate and return the :term:`locale name` associated with
the current request (never cached)."""
try:
registry = request.registry
except AttributeError:
registry = get_current_registry()
negotiator = registry.queryUtility(ILocaleNegotiator,
default=default_locale_negotiator)
locale_name = negotiator(request)
if locale_name is None:
settings = registry.settings or {}
locale_name = settings.get('default_locale_name', 'en')
return locale_name
How can I see negotiator
try to get local from global environment but if it cant to do that its set value from config.
And I cant understand why Pyramid doesn't get locale directly from request's field "Accept-Language"?
And, how can I make a correct determination of the locale?