I18n website: how can I determine the language?

I am working on a website that has some minor internationalization needs (English, French and German), and I want to find out where the user is coming from, so I know what to show. I think the right way to do this is to check the header "HTTP_ACCEPT_LANGUAGE" to find out the language number 1 that the user asks for (and we can safely assume that all users in Germany have browsers that by default ask for DE, etc. ) ..

It is right? Or am I doing something else (I hope nothing is too funny, for example, trying to figure out my country from their IP) ...?

thanks-- Eric

+3
source share
3 answers

If you go to the currently most popular choice - geoIP - without further consideration, you are not making your users a great service.

. IP-? ? ? , , , , : "" , . - - , , , , , , . ( . , Google fr_CA.) , .

:

  • , . :
    • / HTTP- ( Firefox). , , . , , , , .
    • HTTP Accept-Language ( , , , "en" , ).
  • -, . , . , cookie ( ). , , .
  • GeoIP .
+8

, IP- . - -, (, ), , . - , , . , .

0

- geoip ( )

: http://geolite.maxmind.com/download/geoip/api/php/

:

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);
-1
source

Source: https://habr.com/ru/post/1755217/


All Articles