/ Published in: JavaScript
                    
                                        
Select some text to translate, or don't select anything to translate the entire page.
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
/****************************************
Google translate bookmarklet
Select some text to translate, or don't select anything to translate the entire page.
/****************************************/
javascript:(function(){var%20t=window.getSelection?window.getSelection():document.getSelection?document.getSelection():(document.selection&&document.selection.createRange)?document.selection.createRange().text:'';if(t!=''){t=encodeURIComponent(t.toString());window.open('http://translate.google.com/translate_t?sl=auto&text='+t)}else{location.href='http://translate.google.com/translate?sl=auto&u='+encodeURIComponent(location.href)}})()
//Here it is expanded so you can read it:
javascript:(function(){
var t = window.getSelection ? window.getSelection() :
document.getSelection ? document.getSelection() :
(document.selection && document.selection.createRange) ? document.selection.createRange().text :
'';
if(t != '') //if text has been selected
{
t=encodeURIComponent(t.toString());
window.open('http://translate.google.com/translate_t?sl=auto&text='+t) //translate the text in a new window
}
else
{
location.href='http://translate.google.com/translate?sl=auto&u='+encodeURIComponent(location.href) //translate the page in the current window
}
})()
Comments
 Subscribe to comments
                    Subscribe to comments
                
                