views:

35

answers:

2

I'm using $_SERVER["HTTP_ACCEPT_LANGUAGE"]to detect the browser language, which works fine for Firefox and IE:

Firefox:
de,en-us;q=0.9,en;q=0.7,ru;q=0.6,ro;q=0.4,hu;q=0.3,zh;q=0.1

Internet Explorer:
de

Unfortunately, it doesn't work for the following browsers:

Opera:
en,en-US;q=0.9,ja;q=0.8,fr;q=0.7,de;q=0.6,es;q=0.5,it;q=0.4,pt;q=0.3,pt-PT;q=0.2,nl;q=0.1,sv;q=0.1,nb;q=0.1,da;q=0.1,fi;q=0.1,ru;q=0.1,pl;q=0.1,zh-CN;q=0.1,zh-TW;q=0.1,ko;q=0.1

Safari:
en-us

Chrome:
en-US,en;q=0.8

I don't see any fields in the phpinfo output which would be helpful. Please let me know if you have any suggestions. Many thanks!

A: 

I don't have all those browsers, but what about $_SERVER["HTTP_USER_AGENT"]?

Firefox:

Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8

Chromium:

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.470.0 Safari/534.3

In my case that's normal because I'm using chromium with en-US and Firefox with it (Italian)

dierre
A: 

Hi MrG, I don't quite understand what doesn't "work" for you here. All browsers send relatively sensible and syntactically correct Accept-Language headers. Opera most likely sends what it is configured to send in "Preferences > General > Language > Details". If you want your Opera to request a different language or prioritise them differently, this is where you go to change it.

hallvors
I am aware of the possibility to set the language in each browser. But I'm aiming at non-geek users which won't configure such things manually. Hence I was hopping that browsers automatically use the same settings as the operating system.
MrG
Opera's settings are influenced by Opera's UI language (and in preferences, the default/simple option lets the user set both at the same time). Naturally, the installation will usually default to whatever language the OS is in (if Opera is translated to said language).I'm not sure if there is any meaningful difference between getting the language information from the OS compared to from the language the user selected for the browser itself.That said, if you haven't configured Opera's language setup I have no idea where it got all the information in your header.. !??
hallvors