In a couple of the codebases I run, we used to have code along these
lines to discover the browser's preferred language:
accept_lang_matches = request.accept_language.best_matches()
if accept_lang_matches:
locale = accept_lang_matches[0]
else:
locale = 'en'
In a recent release of WebOb, accept_language.best_matches() was
removed, so this code broke.
In the WebOb release notes, I saw:
Accept.best_matches() is gone; use list(request.accept) or
request.accept.best_match(..) instead (applies to all Accept-*
headers) or similar with request.accept_language.
I took this to mean that we should do:
locale = request.accept_language.best_match(
request.accept_language, 'en')
... there was a bug preventing that, so I submitted a patch for it,
which did get merged:
https://github.com/Pylons/webob/issues/5
but in the meanwhile I apparently wasn't doing the right thing (even
if
my fix was right ;))? What's the proper way to select the browser's
preferred locale, defaulting back to English?
Thanks!
- Christopher Allan Webber