On Feb 9, 2009, at 1:08 AM, Uwe Feldtmann wrote:

My browser sends the following accept-language string in the header

Accept-Language: en,en-us;q=0.8,ar;q=0.5,ta;q=0.3

what I get printed is this:

header: en,en-us;q=0.8,ar;q=0.5,ta;q=0.3
lang: ['en', 'en-us']

When I should get this:

header: en,en-us;q=0.8,ar;q=0.5,ta;q=0.3
lang: ['en', 'en-us', 'ar', 'ta']

Am I doing something wrong?
Any pointers?

Here's what's going on. Pylons has a default Request language, this should be the language your templates are actually in. That lang string is expected to be passed to gettext, and if the user prefers 'en' or 'en-us' and your default template language is 'en-us' (Pylons request default), then you actually don't want gettext continuing to search for more languages because your default template strings *are* 'en-us' so the entire site should be displayed in English since its entirely available in English.

When you do request.languages, webob's best_matches with the fallback of 'en-us' is provided:
http://pylonshq.com/docs/en/0.9.7/thirdparty/webob/#webob.acceptparse.Accept.best_matches

If your templates however are not in English, you should set the Request default to the language setting they are in, in your config/ environment.py:
config['lang'] = config['pylons.request_options']['language'] = 'ta'

That will appropriately setup the fallback to the language the templates are in.

That in short is why the lang string is getting cut off at 'en-us'. If you need the entire parsed lang list for other purposes (not using with gettext), call the webob method directly:
request.accept_language.best_matches()

Cheers,
Ben

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to