Google Translate Bookmarklet


/ Published in: JavaScript
Save to your folder(s)

Select some text to translate, or don't select anything to translate the entire page.


Copy this code and paste it in your HTML
  1. /****************************************
  2. Google translate bookmarklet
  3.  
  4. Select some text to translate, or don't select anything to translate the entire page.
  5. /****************************************/
  6.  
  7. 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)}})()
  8.  
  9. //Here it is expanded so you can read it:
  10. javascript:(function(){
  11. var t = window.getSelection ? window.getSelection() :
  12. document.getSelection ? document.getSelection() :
  13. (document.selection && document.selection.createRange) ? document.selection.createRange().text :
  14. '';
  15. if(t != '') //if text has been selected
  16. {
  17. t=encodeURIComponent(t.toString());
  18. window.open('http://translate.google.com/translate_t?sl=auto&text='+t) //translate the text in a new window
  19. }
  20. else
  21. {
  22. location.href='http://translate.google.com/translate?sl=auto&u='+encodeURIComponent(location.href) //translate the page in the current window
  23. }
  24. })()

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.