开发者

How to use google translate to translate website automatically using geoip

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.开发者_Python百科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.


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜