New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
using Accept-Language in the default locale negotiator #1398
Comments
FWIW, in another framework I use, the Accept-Language request header is used to determine a language. The priority of determining a language in the other framework is:
I think your suggestion is a good idea, but I'd get at least one more contributor to comment on this. |
@stevepiercy Which framework is that? One issue I'm seeing now is that I think it'd be nice to standardize a way in the configuration to specify what languages are available for matching against, though. |
What about a format like the following:
The settings would be split by line feed and then each line is split by the first whitespace. The rest of the line is plain human language to use for display in user's code (ex. a drop down to select a language to set the |
I don't think there is a single set of "available languages, FWIW. Something like the above is described in http://docs.pylonsproject.org/projects/pyramid/en/1.5-branch/narr/i18n.html#detecting-available-languages but it's really a "per-application" setting. |
@mcdonc - yes, I know. What I'm saying is creating a single definition for use in the default language negotiator. Then the default language negotiator can be a little smarter about matching languages when reading the "Accept-Language" as it may list more than one option. Ex. |
@tisdall the framework is Knop written in Lasso by a Swede who really knows his räksmörgås. Here's an example of its implementation. The language object has a default language name using ISO-639 and ISO-3166 by convention. One can either dynamically insert language strings into a language object, or insert the language strings via a config file. Anyway, if I understand @mcdonc and the docs correctly, there is no opinion but there is a suggestion of how to implement what you want. You could use that suggestion to split on lines first, then parse the line to get both the language code and its human-friendly name. I think this would be at least a good pyramid_cookbook recipe. There are a couple of implementations through mako and chameleon already. I really don't know enough about Pyramid and this topic to have an opinion about its adoption into the core. |
I don't seem to be getting my point across very well in Pylons#1398 so I'm throwing together this PR to demonstrate what I'm saying. The default_locale_negotiator now looks at a `pyramid.available_languages` value to know what possible languages values are acceptable. Also, it will now use that value to match against `Accept-Language` http request headers if no `_LOCALE_` value is found. Backwards compatibility: If no `pyramid.available_languages` is set then the `_LOCALE_` value is returned as before or `None`. (The `Accept-Language` is ignored as there's nothing to match against) Obviously this needs some work, docs, and tests... I thought it'd be easier to see what I was talking about with a solid example.
@mcdonc @stevepiercy - I added a simple PR to better explain what I'm proposing |
We did the language list approach exactly like that (available_languages in .ini); however there is a problem with the matching that for example Chinese locales have complicated names, and we needed to match everything that could possibly come from the client with whatever our locale names were and it wasn't eventually pretty at all. |
This definitely belongs in a recipe instead of in core but it'd be really nice if someone could write up an example for the cookbook or even as part of the i18n chapter. For example update http://docs.pylonsproject.org/projects/pyramid/en/1.6-branch/narr/i18n.html#detecting-available-languages with a snippet negotiator that used |
I do not have time now, but here is a starter for someone:
|
It's been a while but I think that adding support for |
Is there a rational behind not using the
Accept-Language
values in a HTTP request as a fallback in thedefault_locale_negotiator
? I understand the preference of using a_LOCALE_
value over theAccept-Language
as there seems to be issues with people properly setting that value, but why not use that value when there's no_LOCALE_
set? I think a lot of browsers set that browser's language automatically on install based on the OS's settings so it typically defaults to a reasonable value.I wanted to see if there was some reason for this before submitting any sort of pull request.
The text was updated successfully, but these errors were encountered: