2007/11/02

Google Translation Buttons

Google offers a list of bookmarklets that you can drag to your browser's links bar and that allows you to translate the current page from a language to another language.

"While surfing the web, if you find a piece of text you'd like to translate, select the text with your mouse and click the browser button. If you want to translate a whole web page, simply click the button."

Here is the code...

<script type="text/javascript">
function googleTranslate(lpair) {
var t=(
(window.getSelection&&window.getSelection()) ||
(document.getSelection && document.getSelection()) ||
(document.selection && document.selection.createRange &&
document.selection.createRange().text)
);
var e=( document.charset || document.characterSet );
if(t!=''){
location.href=
'http://translate.google.com/translate_t?'+
'text='+t+'&hl=en&langpair='+lpair+'&tbb=1&ie='+e;
}else{
location.href=
'http://translate.google.com/translate?'+
'u='+escape(location.href)+
'&hl=en&langpair='+lpair+'&tbb=1&ie='+e;
};
} //end_of_googleTranslate()
<script>

Then to use it on your page, simply add a simple link like this:
<a href="javascript:googleTranslate('en|fr');">voir cette page en France </a>

Demo: Click here to view this page in France

No comments:

Monetize Your Web!