Forgot your password?

Easily Translate Any Website with the Google Translate Bookmarklet

 Capture on 06-06-2011 23-26-23 Capture on 06-06-2011 23-52-51 

I have gotten quite hooked on bookmarklets since I discovered that they work nicely on the WebKit browser in BlackBerry OS 6. The latest one I have been playing with is a Google Translate bookmarklet. I happen to read a few Spanish, Hebrew, and other language sites and find I sometimes need a rough translator in the browser. Google was kind enough to give me the starting point with what they call Google Translation Browser buttons but they sadly did not work for me on the BlackBerry Browser though they do work in Firefox.

Capture on 06-06-2011 23-24-54  Capture on 06-06-2011 23-25-54 

I found I had to edit the code a bit to get it to work properly for me. I created two different bookmarklets for English translation with one that opens it up in a new window and one that replaces the current window with the translation:

The bookmarklet is smart enough to know if you have text highlighted if you only want to translate the highlighted text. If you need help making one of the many other Google Translate languages work let me know. It is relatively painless replacing the main to “location.href” references with “” for a new window or “window.location.replace” for the same window. I also found it worked better if I replaced the equal sign after that method with prentices.

For example Google’s Browser button for Spanish translation of

javascript: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=''+t+'&hl=en&langpair=auto|es&tbb=1&ie='+e;}else{location.href=''+encodeURIComponent(location.href)+'&hl=en&langpair=auto|es&tbb=1&ie='+e;};

Becomes this for a new window

 javascript: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!=''){''+t+'&hl=en&langpair=auto|es&tbb=1&ie='+e);}else{''+encodeURIComponent(location.href)+'&hl=en&langpair=auto|es&tbb=1&ie='+e);};

or this for the same window

 javascript: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!=''){window.location.replace(''+t+'&hl=en&langpair=auto|es&tbb=1&ie='+e);}else{window.location.replace(''+encodeURIComponent(location.href)+'&hl=en&langpair=auto|es&tbb=1&ie='+e);};

Once again to add the bookmarklet you need to hover over the link in the BlackBerry Browser and select “Add Link to Bookmarks”. You can then hit the K button or go to your bookmarks whenever you are on a page you wish to translate. Select the bookmarklet and it will translate the page!

8 total comments on this postSubmit your comment!
  1. Very helpful and useful review! I rely very heavily on my bookmarks and until the BerryReview feature didn’t even know this stuff existed!!!!!! Now I feel invicible in my lil 9780’s browser! Thanks BerryReview! Another great tip!

  2. Great! This will be useful for sure. Thanks a lot!!

  3. Use it while you can. I read a week or so ago that the translate APIs were being or are deprecated. So won’t be long before all the translation software (tons on iProducts) that use the APIs will cease to work. This would fall into that category.

    • As far as I know this does not use the translation API’s it simply uses Google Translate. The API’s are what applications use. This just forms the appropriate Google Translate query URL from the current page.

  4. This is a great tip. Thanks

  5. The bookmarklet works, except it leaves a blank page in the original with the folowing:

    [object Window]

    Any suggestions?

BlackBerry© is a registered Trademark of BlackBerry Limited. BerryReview is in no way affiliated with BlackBerry Limited though sometimes their lawyers send us love letters...

Copyright © 2007-‘2018’ BerryReview LLC