Safari http-accept-language

written by Cyx on April 11th, 2007 @ 08:28 AM

Recently I’ve been working with a Globalized rails application. I’ve been testing the app heavily, and often bouncing back between internet explorer and Firefox in order to make sure things are working.

After my latest upload though, the client said that the application was throwing an application error. I asked which page. He said the homepage. That made me wonder a lot.

After some hours I suddenly realized that maybe he was using Safari or some other browser. So I tried safari. There it was. The application error.

It boiled down to the ff lines of code:

request_language = request.env['HTTP_ACCEPT_LANGUAGE'] request_language = request_language.nil? ? nil : Locale.normalize(request_language[/[^,;]+/])

What happens is in Firefox the HTTP_ACCEPT_LANGUAGE is in the format

en-us,en;q=0.5

Whereas in safari, its just a plain en.

I added an additional case checking if the string matches two chars in the iso format. Hope this works for all browsers, will have to check Opera and Konqueror probably, which I’ve added somewhere in my personal todolist

Post a comment