« Discounts and approved supplier lists | Main | Our new .eu top level domain »
June 18, 2006
Finding the language preference of a web site visitor
I can (and do) identify the country of origin of over 98% of the visitors to our web site using the maxmind database. But does that tell me what their native language is? No - it only gives me a clue.
A further clue is available from the accept-language header that's returned by browsers, and is available in PHP in the variable $_SERVER[HTTP_ACCEPT_LANGUAGE]. With this variable, your web site can check if the user has expressed a language preference (and perhaps given a second and third choice too), and you can use the information to tailor your response as appropriate.
I've put up sample source code and a working demonstration on our web site. I've also added a page reporting language statistics for our own site ... only a very short data sample on there today, but as from tomoorow it will update daily with a 24 hour report.
Some surpises ... I would expect to find most major European countries choosing their own langauges, with Swiss visitors choosing between German, Italian and English. The first tests I ran, though, gave me a series of pages called up from the USA with a first choice language of Korean. Truly, the world is a global market.
Posted by gje at June 18, 2006 07:17 AM
Comments
A few days "in" and I've been reviewing the statistics generated by this page from out site. Although 99% of UK visitors who express a preference expressed it for English, we've also had visits from the UK looking for pages in French, German, Greek, Chinese, Swedish, Dutch and Hungarian all in the last 24 hours.
It's also very interesting to note the spread of language requests from countries such as Canada and Belgium where there are several official languages, and to see communities all around the world using the web to search for material in their own native language.
Posted by: Graham at June 21, 2006 06:55 AM