-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
LanguageAccept.best_match() - better fallback #450
Comments
Babel has a function
Since the function is rather big it probably wouldn't be a good idea to include it in werkzeug. Might be worth mentioning it in the docs of Flask-Babel though since it's more useful than the current example using |
This leaves out matching based on quality though. So this solution isn't technically correct. I'm not really sure whether it is preferred for the fix to be in werkzeug or in babel. best_match does do quality matching, but babel doesn't. |
I had problems matching various german accept_languages, foreinstance de-de, de-at. This seems to work for me (all de-de or de-at will be 'de'): `
` |
I'm not sure this covers every case. If my application defines locales as lang_territory and the browser sends a request as lang_territory where only lang matches: from babel import negotiate_locale
AVAILABLE_LOCALES = ['en_US', 'de_DE']
negotiate_locale(['en_EN'], AVAILABLE_LOCALES) # returns None Isn't this the typical use case? Or am I missing something? |
No, the @ThiefMaster snippet is correct as an The @lafrech case also should work. |
Just stumbled upon this behaviour and thought/think it is a bug, as it does not fall back to e.g. 'de' if only 'de-AT' is in request.accept_languages. |
I've already submitted a PR: #1020. ⌛️ |
Any updates on this? |
I thought #1065 has done the work. cc @ThiefMaster |
Though #1065 merged, this still persist in 0.14.1. I am now using |
I've submitted a PR for this, would love to get feedback. |
The negotiate_locale() workaround doesn't even work as expected by this thread. e.g. It also doesn't know how to handle more extended forms of locales, such as those including the script (e.g. zh_Hant_TW). |
And remove some locale-handling code that has been implemented upstream. (pallets/werkzeug#450) Signed-off-by: Aurélien Bompard <aurelien@bompard.org>
Both those calls return
None
. I'm not sure if there's a RFC specifying the behaviour for this but shouldn't a territory-less language always work if there's no exact match available? I.e. if the client specifieden-us
,en
would be fine and more important, if the client specifieden
and the server just knowsen-us
that one should be used.This is important in cases like the following one: There's an application using Flask-Babel which has english as its native language (i.e. hardcoded) because it's nice to keep code in english and a translation, e.g. german. That language is the default language though (because the main audience of the site speaks german). However, if a client sends an Accept-Languages for
en
(or anyen-*
) the english "translation" should be used. But without specifyingen
and allen-*
language codes when callingbest_match()
it will returnNone
(orde
depending on the passed arguments) instead - even though the user's header clearly says he prefers english.The text was updated successfully, but these errors were encountered: