If I was doing it i would maybe check the HTTP_ACCEPT_LANGUAGE for the defult then provide the user an option to change their language and set that in a cookie\session.
The W3C recommends this also - and warns that the site ought not to make any further assumptions about the user's circumstances unless the risk of being wrong is acceptable.
dagon wrote:A German in the US could have their browser set to English but prefer the German version of a web site.
The W3C uses German as an example - the user's browser sends "de" as the preferred language, so the site guesses the user would prefer prices to be listed in euros (despite the fact that there are more than four million German-speaking Swiss).
I'd take that a step further, and as well as offering the option to change language I'd make a note about the fact that the site uses the browser's setting by default (so that if a user told the browser that Danish was the preferred language, the site would use Danish).
jmansa wrote:$currLocale = substr($currLocale, 0, 5);
This isn't very robust: language tags can be anything from two characters long and up ("tpi", "yue-HK", "es-419" are all legitimate). Something you might like to try is to recognise quality settings as well, and sort them from highest to lowest - try each one until you find one you support. (Explode the header on commas to separate the language tags. For each element of the result, the language tag is the bit before the semicolon, and the quality is the number after the "q=" after the semicolon. If it doesn't have an explicit quality setting then the default to use is 1.)