I need a way to determine the main language set in a browser. I found a really great solution for PHP but unfortunately I’m using Django / Python.
I think the information is within the HTTP_ACCEPT_LANGUAGE attribute of the HTTP Request.
Any ideas or ready-made functions for me?
You are looking for the
request.METAdictionary:The WebOb project, a lightweight web framework, includes a handy accept parser that you could reuse in this case:
Note that installing the WebOb package won’t interfere with Django’s functionality, we are just re-using a class from the package here that happens to be very useful.
A short demo is always more illustrative: