[Tutor] CGI-script and multilingual output (HTTP_ACCEPT_LANGUAGE)

Olli Rajala olli.rajala at gmail.com
Sat May 21 12:17:04 CEST 2005


Well, I'm thinking about providing my site (at least some part of it)
both in Finnish and English and would like to do it right. So, I
decided that maybe I should try to use HTTP_ACCEPT_LANGUAGE, or am I
completely wrong?  I have some questions about it, though. I can
access it through os.environ['HTTP_ACCEPT_LANGUAGE'] but have no idea
how I should parse it. I mean, for example from my Firefox the output
is like this 'fi,en;q=0.5' and because I'm not very good programmer, I
don't know what would be the best way to check if surfer wants it in
Finnish or in English.

I could do something like this.

languages = os.environ['HTTP_ACCEPT_LANGUAGE'].split(',')

for temp in languages:
  if temp[:2] == 'fi' or temp[0:2] == 'en'
    language = temp[:2]
    break

But I just doubt that it isn't the best or the right way to do it.

I tried some Googling, but because don't know the proper terms, it
wasn't very successful. So, any ideas would be very welcome!

Yours, 

-- 
Olli Rajala <><
Tampere, Finland
http://www.students.tut.fi/~rajala37/

"In theory, Theory and Practice should be
the same. But in practice, they aren't."
- Murphy's Proverbs


More information about the Tutor mailing list