La mejor manera de determinar el idioma del usuario [duplicado]

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. Utilice las $_SERVER['HTTP_ACCEPT_LANGUAGE'] a través de 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).

preguntado el 09 de septiembre de 13 a las 23:09

Ask them. You could use the GEOIP but it will only tell you country or continent, and in a country there may be dozens or hundreds of languages and dialects. You really need to just ask or make some assumptions. -

Google uses the accept language header to determine language preference. This also makes most sense, it works better than geolocation via IPs which is not so well for languages. As this has been discussed earlier please use the search and refer to the existing material when you ask about the same topic. -

Further ref: What's the best way to determine users' preferred language? y Patterns for creating a Language Switcher? - what you ask about is more webmastering material than programming IMHO. -

2 Respuestas

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.

Respondido el 09 de Septiembre de 13 a las 23:09

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.

Respondido el 09 de Septiembre de 13 a las 23:09

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.