Reputation: 5791
i heard about many ways that depend of files like csv or database but i think uploading an extra database on my site to do that is not good idea i feel good about the external providers is useing externial site that give your the country by the ip is good way or its not good because the server will wait the response of the external provider and this will slow down the site?
Upvotes: 0
Views: 432
Reputation: 19393
I wouldn't use GeoIP for this - there are too many scenarios when it fails or produces the wrong results.
As @Paul says the HTTP Accept-Language header specifies the user's language preferences as defined in the browser. You can view what your browser is set to by visiting Browser Language Detection.
For a real worked example see Parse Accept-Language to detect a user's language.
Also remember that crawlers don't use Accept-Language so it is important to ensure that you have a strategy for making this available (e.g URLs for each language content) and include in sitemap.
Also see Apache Module mod_negotiation for content selection.
Upvotes: 1
Reputation: 22862
I would use PHP variable $_SERVER['HTTP_ACCEPT_LANGUAGE'] which, in my case, holds this value sk,cs;q=0.8,en-us;q=0.5,en;q=0.3.
That means, my browsers language is 'Slovak'.
I think, this option is better. Just imagine, that you are English, but you are on vacation somewhere.
You use your notebook over there... Your IP address would tell your server, that you are in Croatia and you'd like to get content in their language... But you browser still says you are english speaking person... There is the difference ;)
Upvotes: 1
Reputation: 36319
It's actually not a great idea to base the language choice on the IP address anyway. What if I'm an American browsing from Germany, and I don't speak German very well? Your most standards-compliant way (I think) would be to parse the Accept-Language header of the web request, and use that to set a user's default, but always provide them a way to override the default and pick their language (which you'd then store in their session or user prefs)
Upvotes: 1