views:

236

answers:

1

I have been looking around the internet for a script which would use google translate api to translate a website automatically through a geoip script without the need of clicking translate button. Since google does provide a small div snippet which you can add to your website and then through a drop down menu you can choose the language and click translate and it translates the whole website.

the snippet is here http://translate.google.com/translate_tools?hl=en&layout=1&eotf=1&sl=ru&tl=en

How can i integrate a geoip script along with the above snippet or there are also a couple of google translate scripts available on the internet.

A: 

Using geoip to determine user's language is not optimal way, because people may speak/prefer different language than the main language in their geographical location.

Accept-Language header sent by client is something you would like to use, but it's not available in javascript (at least in any standard way).

However, there's available navigator.language which tells us the language of browser UI. Though not ideal, this is very easy to implement:

<a href="#" onclick="window.location.href = 'http://translate.google.com/translate?u=' + encodeURIComponent(window.location.href.replace(/#.*$/, '')) + '&langpair=auto|' + navigator.language.split('-')[0];">Translate</a>
jholster
i tried this code but it didnt work as i am wanting it to be.
AK
It didn't work at all or you want it to work without clicking a link?
jholster
I dont think it worked or maybe i did something wrong. I want it to work without clicking the link and not getting forwarded to a page where it says google translate.
AK
Well, it was merely an example of implementation.
jholster