[mod_python] Language selection

Jim Gallacher jpg at jgassociates.ca
Mon May 22 09:53:55 EDT 2006

Wouter van Marle wrote:
> Hi all,
> I know it's possible through the http request for browsers to indicate
> preference for a language.
> Can anyone explain how that works? Or are there code snippets available
> for mod_python?
> My website now supports four languages (English, Dutch, Chinese
> Simplified, Chinese Traditional), defaulting to English. If the user
> wants another language, they have to select it manually. It'd be nice if
> I can detect there preference and default to that.

You want to examine the Accept-Language header, which will likely be set 
by the browser. See RFC-2616 at http://rfc.net/rfc2616.html#s14.4

Note the important caveat in the RFC:

    As intelligibility is highly dependent on the individual user, it is
    recommended that client applications make the choice of linguistic
    preference available to the user. If the choice is not made
    available, then the Accept-Language header field MUST NOT be given in
    the request.

Sorry, I don't have any code snippets.

More information about the Mod_python mailing list