Reputation: 5215
I'm working on a web site that has some minor internationalization needs (English, French and German), and I want to figure out where the user is coming from so I know which to display. I think the right way to do this is to check the "HTTP_ACCEPT_LANGUAGE" header to find out the #1 language the user is requesting (and it's safe to assume that all users in Germany have browsers that default to asking for DE, etc.).
Is that correct? Or do I have do something else (hopefully nothing too ridiculous, like trying to figure out their country from their IP)...?
thanks-- Eric
Upvotes: 5
Views: 3225
Reputation: 7519
If you go for the currently most popular choice -- geoIP -- without further consideration, you're not doing your users a great favour.
Languages and countries do not overlap. What are you going to do with users from Swiss IP addresses? Belgium? Canada? If you go for the majority language in each case, you'll annoy repeat visitors who happen to be part of large linguistic minorities: they'll be greeted in the "wrong" language each and every time, even though the site is available in their preferred language. The same is true for expats -- and from experience, it is extremely disconcerting to be greeted in, say, Swedish just because I happen to travel to Sweden. (And even big sites get it wrong. The other day I arrived at Vancouver airport from London and Google switched me to fr_CA.) Don't forget that a large number of people are multilingual or non-native speakers of majority language of their country of residence.
Here are the guidlines I follow:
Upvotes: 11
Reputation: 1897
I'd check both the accept language header and the originating country of the IP address of the visitor. If the accept language header is anything but english (probably the most used default setting), use that to set the default language. If the accept language is english, use the originating country to set the default language. I think this will give you a more educated guess at the visitors native language.
Upvotes: 0
Reputation: 519
You pretty much answered your own question - you can either use that header OR just geoip (it's dead simple to use)
Download from: http://geolite.maxmind.com/download/geoip/api/php/
Sample code:
include("geoipcity.inc");
include("geoipregionvars.php");
$gi = geoip_open("GeoLiteCity.dat", GEOIP_STANDARD);
$record = geoip_record_by_addr($gi, $user_ip);
echo "The users country code is:" . $record->country_code;
geoip_close($gi);
Upvotes: -1