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.
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 “window.open” 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='http://translate.google.com/?text='+t+'&hl=en&langpair=auto|es&tbb=1&ie='+e;}else{location.href='http://translate.google.com/translate?u='+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!=''){window.open('http://translate.google.com/?text='+t+'&hl=en&langpair=auto|es&tbb=1&ie='+e);}else{window.open('http://translate.google.com/translate?u='+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('http://translate.google.com/?text='+t+'&hl=en&langpair=auto|es&tbb=1&ie='+e);}else{window.location.replace('http://translate.google.com/translate?u='+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!

xAshley1983x ( View Profile) - Posts: 1007
Posted: June 7, 2011 at 10:42 AM EST from my BlackBerry 9780 | OS 6.0.0.448
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!
PiotrJot ( View Profile) - Posts: 8
Posted: June 7, 2011 at 11:25 AM EST from my BlackBerry 9700 | OS 6.0.0.576
Great! This will be useful for sure. Thanks a lot!!
devguy Not Registered
Posted: June 7, 2011 at 12:40 PM EST
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.
Ronen Halevy ( View Profile) - Posts: 3408
Posted: June 7, 2011 at 12:54 PM EST
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.
Tango1 ( View Profile) - Posts: 93
Posted: June 7, 2011 at 3:49 PM EST
This is a great tip. Thanks
Stacey Not Registered
Posted: November 18, 2011 at 11:24 AM EST
The bookmarklet works, except it leaves a blank page in the original with the folowing:
[object Window]
Any suggestions?
Ronen Halevy ( View Profile) - Posts: 3408
Posted: November 18, 2011 at 11:52 AM EST
So what does work?
Stacey Not Registered
Posted: November 18, 2011 at 11:55 AM EST
A new windows DOES open with the translated page but the original is left blank with:
[object Window]
this makes it difficult to compare them.
If you’re going to open a new tab then leave the original intact