views:

428

answers:

6

Hello, title is pretty clear.

My websites consists of both English-written and Spanish-written versions. You can go to the main site, which is in Spanish, by clicking http://www.chrishonn.com and to the translated version, which is in English, at http://en.chrishonn.com. At the index of each page there is a link (at the bottom) which allow the user to pass from one site to the other.

However, I was wondering, how do big sites like Google, Yahoo!, and other brands' websites to recognize the user's geographical location/IP so that - depending on that - the site's language is adapted (i.e. you are from China and you visit www.google.com, you'll be redirected to www.google.cn).


I have stated on every single page of my website the language:

<meta http-equiv="content-language" content="en">

That example is of course from one of the http://en.chrishonn.com sites, which are in English.

I hope someone can give me a hand. Thank you (if I missed something, please let me know).

+3  A: 

As for Google, your location is determined from your IP address. A request to google.com from outside the US returns an HTTP/1.1 302 Found which redirects you to your country specific domain.

As also discussed on another post, doing these kinds of redirects can make SEO tricky and complicated. I suggest reading Matt Cutt's article (a Google software engineer) on how Google handles the 302 Redirect: SEO advice: discussing 302 redirects.

Different search engines handle the 302 redirect in a different way. With 302 redirects, you may risk having your original domain ignored by search engines.


If you want to determine your users' location from their IP address, there are many off-the-shelf services which basically map most of the IP ranges to countries. You may want to check:


Another popular technique is to parse the Accept-Language HTTP header, which contains information about the user's language preferences. Mainstream browsers allow these language preferences to be modified by the user. You may read more about this technique from:


Daniel Vassallo
dusoft
Well done for noticing :) Yes, I copied a part from an answer I gave to another question on a similar topic.
Daniel Vassallo
I edited the post with the reference. Just in case someone else senses the deja-vu :)
Daniel Vassallo
Thank you very much. I am downloading GeoLite Country and I'll have to figure out how to enable it ;).Will update you ASAP.Thank you again.
Hobhouse
+1  A: 

some website use IP address-based geo location, some us Accept language header (can be set in the browser). Anyway, from the usability point of view - always allow people to change the language and never display different content on the same IP (google and other search engines doesn't like it and it would be bad from SEO point of view).

dusoft
+1  A: 

These sites often use tools that are generically called "geolocation software".

One of the most popular packages is the free GeoLite Country database offered by MaxMind. This will integrate into your application and provide IP-to-country lookups. With Apache, you will have some environment variables set called GEOIP_COUNTRY_CODE and GEOIP_COUNTRY_NAME.

All your application has to do after that is decide where your user should be or what settings they should have by default based on the country, and redirect or output appropriately.

zombat
Thank you very much. I am downloading GeoLite Country right now. I will also check how to enable it, as I am pretty new to these sort of databases.
Hobhouse
+6  A: 

Rather than detecting the location of IP address (often unreliable due to NAT and proxying) you could check the default language the browser is set to. There are JQuery plugins to support this, such as http://keith-wood.name/localisation.html, or use server-side code to read the HTTP request header "HTTP_ACCEPT_LANGUAGE" to determine if you want to show the ES or EN site.

AUSteve
+1 for Accept-Language, which is a **much** more suitable way to choose a language than geolocation (even if geolocation were 100% accurate). However, it should only be done on the server side. Accept-Language is not available on the client side; instead you only get `navigator.[user]Language`. However this setting is to do with the install language which, unlike the Accept-Language, is not easily user-configurable. Consequently it — and this plugin which uses it – should never be used.
bobince
I would have done this, indeed: For its simplicity and it'd have taken less time. However, many people (count me in) use another language in our browser(s)/OS(s) than the language we actually speak, or the country's official language.
Hobhouse
@crozer: shouldn't you be most interested in what language the user requests to browse data in instead of their location? I would think that the `Accept` header is the most indicative of the user's wishes.
D.Shawley
@bobince: I'd go with server-side too, I mentioned the JQuery plugin because the question didn't reference any server-side technology, only "html" and "javascript".
AUSteve
Instead, why don't you read my last comment below :)I don't wanna sound rude, but since I already wrote this code, could you please try it? If it does not work, I will do what you say here.I would really appreciate this.Thank you
Hobhouse
A: 

As I commented above, I've downloaded MaxMind GeoIP Country .CSV databse (I hope this is the best option, otherwise just tell me and I will download the binary one).

MaxMind.com offers me a simple guide on how to implement this databse into my SQL databse, but this won't get me to what I am looking for (I have to add this to my website itself, and/or server; I don't think I'll just have to run a SQL-query will I?)

In other words, I understand what they are saying, but I don't think I am on the right track. Could anybody help me out?

Thank you once again for all your support. I will keep reading those instructions.

cr0z3r
Never mind, I have found a few tutorials that are guiding me through a few PHP scripts that should accomplish what I am looking for.Thank you all.
Hobhouse
Hello,I have done the coding. However, as I don't live in any of the countries stated in my code (US, GB, AU, CA, etcc) I would like to ask you to go to http://www.chrishonn.com and let me know if the site redirects you to http://en.chrishonn.com.I added a geoip folder into my website and a PHP script inside my index.html which enables the files inside that folder.I am just hoping the following code is valid (the commas between the country-codes:>> if($country_code == 'US,GB,AU,CA,IN') <<
Hobhouse
No sorry, I get the www version (I am in AU).If you want help on implementing MaxMind it's probably worth creating a new question so you'll get more specific help.Good luck keeping the IP list updated...
AUSteve
Hey, thanks for checking.I think I might know why this is not working:does this PHP script work?>> if($country_code == 'US,GB,AU,CA,IN')I have no advanced knowledge of PHP, and the example only stated ONE country-code (i.e. if($... == 'US').
Hobhouse
Checked from home PC too, no good. Most likely cause is IP location detection - as mentioned it's not going to be 100%. I'm a Dot Net Nerd so I can't help with your PHP. You might also want to move your language switching link to the top so users can find it easily.
AUSteve
`if ($country_code=='US' || $country_code=='GB' ...)`, surely? The string will never be equal to one with commas in. Personally I don't get redirected as I am in Germany. If you'd looked at my `Accept-Language` you'd have seen I prefer English. Geolocation is not a good choice for language negotiation.
bobince
@AUSteve: Indeed, I will be doing that soon.@bobince: I guess I will be trying that now. However, you mention using it on the server-side. I know how to include the 'jQuery Localisation' script inside of my page, but that would be on the client-side, I guess? Could you explain this to me a little more, please. Vielen dank ;-)
Hobhouse
A: 

By the way, the method of showing the visitor a language based on their country is pretty tricky since a lot of countries are multi-lingual.

Better to check the Accept-Language which you can also parse for multiple languages in order of preference. I did that with a multi-lingual website that I created for a customer a few years back.

Then if Accept-Language does not contain any languages that you currently support then only you check the country that the visitor's IP address originates from. For this part, you will need data from services such as IP2Location which contains information that are linked to each IP address. Once you have the country, you can just determine what language you should display for that country.

Ariel