Question

I'd like to which way is the best way to guess what is the user's language without asking him. Here are a couple of options that I've found, but feel free to add any other that you think is worth mentioning.

  1. Use $_SERVER['HTTP_ACCEPT_LANGUAGE'] via PHP
  2. Use any Maps API (such as Google Maps or Bing Maps) to determine what country the user is accessing the website from (if he is using a modern browser that support location services) and then detect what is that country's official language.
  3. Have PHP execute a simple shell script (shell_exec()) that send a request to a website like (http://geoip.s12.com.br or similar) to determine what country the user is accessing the website from and then detect what is that country's official language.
  4. I may be wrong about this one because I didn't make a lot of research about it: Use php's GeoIp function to determine what country the user is accessing the website from and then detect what is that country's official language. (http://www.php.net/manual/en/book.geoip.php)

I am aware that the first one will do in almost any case, however I'd like to know which one is more accurate (the way Facebook or Google use to set your language).

Was it helpful?

Solution

I would go with $_SERVER['HTTP_ACCEPT_LANGUAGE'] mainly due to the fact that it is user configurable.

The issue with geo locating, is that language really shouldn't be tied to a location search. Sure, it would allow you to make an educated guess, but I could easily be vacationing in China, or prefer my internet to be in "language x"

Regardless of the method you use for your educated guess, I would definitely still provide the option to choose their preferred language to override your guess.

OTHER TIPS

There are countries with several languages so 2,3 and 4 won't work at all, so for me, the best opion is to use HTT_ACCEPT_LANGUAGE.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top