Google Translation Feature from Google Toolbar also as JS for Opera?

Forums » General Opera topics » User JavaScript

You need to be logged in to post in the forums. If you do not have an account, please sign up first.

Go to last post

7. March 2007, 01:49:56

Stevie1

Posts: 20

Google Translation Feature from Google Toolbar also as JS for Opera?

Hello all!

I wonder if theres a JS for the toolrip translation of the
google toolbar. In Firefox i found it quite handy, since it's an
instant translation.


greets


stevie

7. March 2007, 02:34:45

profiT

Posts: 453

http://translate.google.com/translate_buttons?hl=en

You can find there button provided by Google itself. All you need to do then, drag'n'drop buttons you like to panel you like.
selection2rtf.js -- exporting selection to Word files (with images and some formatting)
Convert2PHF.js -- saving in single htm or mht file

8. March 2007, 04:09:26

Stevie1

Posts: 20

err not quite, i mean something else.
i want instant translation by just hovering over a word.

8. March 2007, 20:10:18

Stevie1

Posts: 20

really no possibilty to do that? sad

10. March 2007, 10:21:53

profiT

Posts: 453

AyushJ
How is that supposed to work? I've installed this script, but see no difference.
selection2rtf.js -- exporting selection to Word files (with images and some formatting)
Convert2PHF.js -- saving in single htm or mht file

10. March 2007, 10:32:07

AyushJ

Posts: 4754

first enable it by clicking on the button at bottom-right. Then select the word with mouse.

10. March 2007, 10:52:05

profiT

Posts: 453

Hmm. I haven't noticed this little thingy down there. All right, i've "enabled" it, list has to be visible, right?

I've tried to select words with double-click. Then selected them with mouse. Tried to hover over words. Nothing...

-----

Hey, it worked!.. Nice!
selection2rtf.js -- exporting selection to Word files (with images and some formatting)
Convert2PHF.js -- saving in single htm or mht file

10. March 2007, 10:58:40

AyushJ

Posts: 4754

Originally posted by profiT:

I've tried to select words with double-select.



Double-Click Select will work if you disable the "Double click text to display context menu" setting in "Preference.. > Advanced > Toolbars"

Originally posted by profiT:

Then selected them with mouse. Tried to hover over words. Nothing...



i dont know how to do that. In IE, it is simple:-Just [create textrange > moveToPoint method > expand the word] but in Opera... how ??

Originally posted by profiT:

Hey, it worked!.. Nice!



thanks..

11. March 2007, 20:32:48 (edited)

Stevie1

Posts: 20

wow cool man, u coded that "quickly"?
ill try it out and give some feedback, thanks!

EDIT:
wow cool! it worked at once. yeah the tooltip-thingy over a word would be cool.
maybe someone can help with the function?

12. March 2007, 14:13:27

AyushJ

Posts: 4754

Originally posted by Stevie1:

wow cool! it worked at once.



once !!

Originally posted by Stevie1:


yeah the tooltip-thingy over a word would be cool.maybe someone can help with the function?




even a small hint will be enough.

14. March 2007, 02:33:28

Stevie1

Posts: 20

from what i read in the german opera forum (www.opera-info.de) theres no possibilty to
catch a word without selecting it sad
they say this functionality which is used in the google toolbar for firefox is based on XUL, and
thats what opera lacks. can you confirm this?

30. March 2007, 04:44:47

addps4cat

Posts: 4

AyushJ's script works very well (Thanks!) but I can't seem to get it to work w/ words with accents. So I try to translate something from spanish to english like "maña" but the output is just "maa" like it omitted the accent from the word entirely. Any help?

30. March 2007, 14:00:30

addps4cat

Posts: 4

Originally posted by AyushJ:

So I try to translate something from spanish to english like "maña" but the output is just "maa" like it omitted the accent from the word entirely.



I can't reproduce it on this page either. I mouse over "maña" here and it works. Try doing it on this page http://forum.wordreference.com/showthread.php?t=239427 and picking any accented word.

http://my.opera.com/addps4cat/albums/showpic.dml?album=231452&picture=3451417

Maybe it is a problem having to do w/ the encoding of the web page. I tried switching that page to UTF-8 and all the accents turned into black diamonds with question marks in them, but that did not happen on this page.

30. March 2007, 17:36:39

addps4cat

Posts: 4

Sweet, thanks a million. Worked like a charm.

31. March 2007, 16:37:52 (edited)

FiSz

Posts: 27

is it possible to add English-Polish and Polish-English translation?

[EDIT]
i guess not google doesn't support translating to Polish. too bad

24. April 2007, 14:46:58

Grrblt

Posts: 34

I'm trying to translate from Japanese to English with Ayush's file. It gives me some %a4%e5 etc text when I select a small chunk of text, and Google Bad Request when I select a big chunk. I think you might have a problem with JS's text encoding. Google's own button gave another interesting result, it tried to translate ????????????????????????????? instead of the text I had selected.

24. April 2007, 15:09:24

AyushJ

Posts: 4754

Originally posted by Grrblt:

I'm trying to translate from Japanese to English with Ayush's file. It gives me some %a4%e5 etc text when I select a small chunk of text


Test Url ??


Originally posted by Grrblt:

and Google Bad Request when I select a big chunk.


It happens with long text. sad

3. May 2007, 05:52:55

kinnik

Posts: 227

Nice script
But only one translate result is too less for me to figure out the meaning.
Can it give back more than one?

For example:

I want to find out what is the meaning of "awake" in chinese.
google give me multiple answers about"awake"


http://www.google.com.hk/search?hl=zh-TW&q=fy+awake

3. May 2007, 07:23:12 (edited)

AyushJ

Posts: 4754

is there a url for that ?

btw, you can also use this google translation script.
Features : AutoSize, Search and Copy buttons in results

Button to enable/disabe script (drag to toolbar):
button

3. May 2007, 13:32:21

igzist

Posts: 47

Thanks AyushJ

Really nice Js.

4. May 2007, 01:55:19

kinnik

Posts: 227

Originally posted by AyushJ:

is there a url for that ?

btw, you can also use this google translation script.
Features : AutoSize, Search and Copy buttons in results

Button to enable/disabe script (drag to toolbar):
button



Here is the en>cht url of google translation:

http://www.google.com.hk/search?hl=zh-TW&q=fy+awake

Thanks

4. May 2007, 05:54:34

AyushJ

Posts: 4754

But that also shows the google results so it doesn't look reliable. Any other url where google only shows the translation ??

9. May 2007, 10:26:01

Grrblt

Posts: 34

Originally posted by AyushJ:

Originally posted by Grrblt:

I'm trying to translate from Japanese to English with Ayush's file. It gives me some %a4%e5 etc text when I select a small chunk of text


Test Url ??


http://forums.narutofan.com/showpost.php?p=8309744&postcount=5

Originally posted by Grrblt:

and Google Bad Request when I select a big chunk.


It happens with long text. sad


Any way around it?

9. May 2007, 13:34:30

AyushJ

Posts: 4754

Originally posted by Grrblt:

http://forums.narutofan.com/showpost.php?p=8309744&postcount=5



Redownload the script then before enabling the script, tick View>Encoding>Unicode>UTF-8

You can enable the script with this button:
Enable/Disable

9. May 2007, 15:34:23

Grrblt

Posts: 34

Tried it and now I can't access the translamagator thing at all sad

9. May 2007, 15:55:42

AyushJ

Posts: 4754

Originally posted by Grrblt:

Tried it and now I can't access the translamagator thing at all



Delete the old script > Download the script again to your UserjS folder > Drag the Enable/Disable button to a toolbar > Load http://forums.narutofan.com/showpost.php?p=8309744&postcount=5 > Choose View-Encoding-Unicode-UTF8 > Click on the Enable/Disable button on toolbar > Select some text - It should work

9. May 2007, 16:30:51

Grrblt

Posts: 34

Gives me %u30B8%u30E3%u30F3%u30D7%u3042%u3052%u305F%u304B%u3089%u8A18%u61B6 %u9B3C%u9BAB%u3055%u3093%u767B%u5834 %u30A4%u30BF%u30C1%u3068%u4F55% sad

I did some detective work; the encoding reverts back to Automatic everytime I click the Enable button.

9. May 2007, 17:13:31 (edited)

AyushJ

Posts: 4754

Originally posted by Grrblt:

I did some detective work; the encoding reverts back to Automatic everytime I click the Enable button.



Strange ..

Open the script and set Default_Enabled to 1
and then change the language to "Japanese to English" :
Remove the start from the line "English to French" and add a star after the "Japanese to English"-
'Japanese to English[B]*[/B]':'ja|en',

Then go to the web-site and change the Encoding then select the text (without clicking on the button)


first redownload the script and try again ::

EDIT: yikes i forgot to upload the updated script !! ... DONE now > Redownload.

9. May 2007, 18:36:41

Grrblt

Posts: 34

Works fine now, even with Automatic encoding. Any chance of getting that button in the corner back? I liked it smile Or some kind of drop-down list to select languages on the new button.

10. May 2007, 00:52:15 (edited)

AyushJ

Posts: 4754

Originally posted by Grrblt:

Any chance of getting that button in the corner back?



The button/language-select elements are back bigsmile : Download Google Translation in Tooltip v1.7.

To turn them off, open the script and set "Show_Buttons" to 0

10. May 2007, 22:43:43

addps4cat

Posts: 4

Is there any way to access and edit the source of the iframe?

Here it creates the iframe:
vrifr=document.createElement("iframe");


And here it sets the iframe to google's translation:
vrifr.src="http://google.com/translate_t?text="+escape(vrselTxt)+"&by=ayush&langpair="+BO.LG+"&ie="+document.charset //translate the text in iframe


Basically what I want to do is use a different translator, like wordreference.com. The problem is that when I change the vrifr.src, it loads the entire webpage into the iframe. I'd like to be able to access the html and edit it down to just the translated words if that is at all possible. Any suggestions?

13. May 2007, 22:33:52 (edited)

Thomas82d

Posts: 104

Thanks alot for this script Ayush, it's awesome.

And addps4cat, I was wondering about the same thing, because I prefer dict.leo.org as translator. But Ayush's script doesn't get the translation by analyzing the whole page, it's just looking up "var vrresb=document.getElementById("result_box")"... since there's no tag (or id or how it's called, I have no clue of html sad ) this won't be possible on wordreference.com or dict.leo.org.
Still, some other way to get to the result would be neat... I know that on dict.leo.org, the result always is declared in the form of <td class="td1" valign="middle" width="43%">##RESULT##</td>... it's the only element with with = 43% (except for the search term itself), so maybe it's possible to extract it with this instead of an id...


EDIT: One more question, the script also activates when I just opened a picture, and then my resizing user js ( http://userjs.org/scripts/browser/enhancements/zoom-image ) doesn't work anymore...
Can you somehow tell the script not to run when the url ends with jpg or bmp and so on?

14. May 2007, 01:09:36

AyushJ

Posts: 4754

Try v1.8 -
+Now you can add more engines easily!
+Script can save the enable/disable and selected language in cookie!
+BabelFish and WordLingo translations !
Translation in Tooltip

15. May 2007, 10:26:31 (edited)

Thomas82d

Posts: 104

Thanks for the update, Ayush. IMHO, this script is actually far superior to the Google toolbar-version Stevie was asking for, as you can for example easily translate whole paragraphs instead of single words. I just have the following questions/suggestions:
First, do you have an idea how to use dict.leo.org as engine? I had a look at the html and at how your script extracts the information from other pages, but I was unable to rewrite the script for this site.
Second, maybe one can use your script for a much broader field of applications? For example for wikipedia-lookups (maybe one can use parts of this script, operapedia, to extract the information, or this script http://en.wikipedia.org/wiki/Wikipedia:Tools/Navigation_popups )... but I'm not sure how much work this would cause, or if it's possible at all.
Well, it's just a suggestion.
Thanks for your efforts, cheers
Thomas

PS. Just one or two small enhancements that I would suggest: First, the horizontal scroll-bar is a little obtrusive, can it be switched off somehow? Also, I'd suggest to set the opacity to 1 per default, and the position to the top left corner of the screen, as seen here.. this way, the translation is always readable idea

edit: oh and btw, your script still breaks this script for me worried

15. May 2007, 11:08:50

AyushJ

Posts: 4754

Originally posted by Thomas82d:

First, do you have an idea how to use dict.leo.org as engine?



Try adding this(only the bold part) after BabelFish in Trans_Engines:
[I]...
    URL:"http://babelfish.altavista.com/tr?trtext=%T&lp=%FROM_%TO"
  }[/I]
		
[B],'Dict.Leo.Org':
  {
    LangPairs:{"Dict.Leo.Org":'x,x'},
    ResultText:function(){return "::HTML::"+document.getElementById("results").innerHTML },
    URL:"http://dict.leo.org/ende?lp=ende&lang=de&searchLoc=-1&cmpType=relaxed&sectHdr=on&spellToler=on&search=%T&relink=off"
  }[/B]
}




Originally posted by Thomas82d:

For example for wikipedia-lookups



I'll try.

Originally posted by Thomas82d:

First, the horizontal scroll-bar is a little obtrusive


It never appears here. Try increasing the Max_Width.

Originally posted by Thomas82d:

Also, I'd suggest to set the opacity to 1 per default


I'll add an option with default 0.9

Originally posted by Thomas82d:

your script still breaks this script for me


Add a "z" before the script name: zTranslation in tooltip...

15. May 2007, 21:42:11

Thomas82d

Posts: 104

Hi again, thanks for the quick reply. So, the dict.leo.org thingy worked somehow when I used "ResultText:function(){var R=document.getElementById("results").textContent;return R }," instead, but it doesn't look pretty (the code you proposed only gave an empty box here :/)
The scrollbar is still here, no matter what MaxWidth I use ( http://img508.imageshack.us/img508/5461/05152007233744nr3.png ), am I the only one with that?
And, regarding the autosizer, I had to delete (or comment) the line "if (document.body.childNodes.length != 1) return; // Not an image" in the script file, changing the filename or "@name" of your script didn't do the trick whistle
Well, thanks anyways, cheers
Thomas

16. May 2007, 11:42:43

AyushJ

Posts: 4754

Originally posted by Thomas82d:

Hi again, thanks for the quick reply. So, the dict.leo.org thingy worked somehow when I used "ResultText:function(){var R=document.getElementById("results").textContent;return R }," instead, but it doesn't look pretty (the code you proposed only gave an empty box here :/)



It works here, Screenshot

Originally posted by Thomas82d:

The scrollbar is still here, no matter what MaxWidth I use ( http://img508.imageshack.us/img508/5461/05152007233744nr3.png ), am I the only one with that?



No problem here :
http://my.opera.com/AyushJ/albums/showpic.dml?album=231319&picture=3936411

Can you send me your script ??

16. May 2007, 12:30:54

Thomas82d

Posts: 104

Hm well the scrollbars are here, even when I just download the script from your page without any editing (Opera 9.20 on Windows XP SP2, if that's important)... see http://img511.imageshack.us/img511/989/05162007141802vq7.png ...
But regarding the dict.leo.org thing: It works like a charm now (yay), this is already one of the most useful userjs in my collection up thanks alot!
Cheers, Thomas

16. May 2007, 15:05:11

HaJotKE

Grumbling Hyper-Critical Cantankerous Curmudgeon!

Banned user

[OFFTOPIC]

Originally posted by AyushJ:

It works here, Screenshot

Can somebody else please check that link...
For me, OPERA is freezing completely, nothing in OPERA is working any more...
I have to kill the OPERA process completely! sad

Tried it several times...
OPERA V8.54 (Win NT4) & V9.27 & V9.52[b10108] & V9.62[b10467] & V10[b1413] standard on (Win 98 SE) / (Win NT4) / (Win 2000 pro)
◇◇ UserJavascript "zz-spoof-id"! ◇◇◇ [Thanks for Finally Considering this Petition!] Composing Emails in the HTML Format in Opera

16. May 2007, 16:52:46

Thomas82d

Posts: 104

Originally posted by HaJotKE:

[OFFTOPIC]Originally posted by AyushJ:It works here, Screenshot Can somebody else please check that link... For me, OPERA is freezing completely, nothing in OPERA is working any more... I have to kill the OPERA process completely!


Hm, well it works for me ( http://img522.imageshack.us/img522/9537/05162007185109ft3.png )... but I was wondering how that image was made, anyways... the whole .jpg is stored in the url? How do you do that?
btw: If you don't want tinyurl.com to auto-redirect you, you can sign up an account there and disable autoredirecting.

16. May 2007, 17:40:43 (edited)

AyushJ

Posts: 4754

Hm well the scrollbars are here, even when I just download the script from your page without any editing


On all sites ??

Originally posted by Thomas82d:

but I was wondering how that image was made, anyways... the whole .jpg is stored in the url? How do you do that?



It's a big data: URI: http://en.wikipedia.org/wiki/Data:_URI_scheme

http://software.hixie.ch/utilities/cgi/data/data

Originally posted by Thomas82d:

If you don't want tinyurl.com to auto-redirect you, you can sign up an account there and disable autoredirecting.



Or just add preview. before the address- http://preview.tinyurl.com/xxxx

16. May 2007, 20:22:47

Thomas82d

Posts: 104

Originally posted by AyushJ:

On all sites ??


Did you mean, with all engines? Just tried it, the error (horizontal scrollbars) occurs only with the google and the babelfish engine, not with wordlingo...

16. May 2007, 21:10:44

HaJotKE

Grumbling Hyper-Critical Cantankerous Curmudgeon!

Banned user

Originally posted by Thomas82d:

btw: If you don't want tinyurl.com to auto-redirect you, you can sign up an account there and disable autoredirecting.

Did you do that?
Because if I go to that link at tinyurl.com OPERA is still repeatedly and reproducible FREEZING... the data: URI is showing and the status bar keeps showing "Sending request to tinyurl.com..."

No further action possible then at my end here...!
Very annoying! sad
OPERA V8.54 (Win NT4) & V9.27 & V9.52[b10108] & V9.62[b10467] & V10[b1413] standard on (Win 98 SE) / (Win NT4) / (Win 2000 pro)
◇◇ UserJavascript "zz-spoof-id"! ◇◇◇ [Thanks for Finally Considering this Petition!] Composing Emails in the HTML Format in Opera

16. May 2007, 23:27:15 (edited)

AyushJ

Posts: 4754

the error (horizontal scrollbars) occurs only with the google and the babelfish engine, not with wordlingo...


Does it happen on particular site or all sites?


HaJotKe: Maybe these are related :
http://my.opera.com/community/forums/topic.dml?id=154751
http://my.opera.com/community/forums/topic.dml?id=144497

btw, the data: url is 32413 characters long !!

17. May 2007, 17:03:56 (edited)

Thomas82d

Posts: 104

Originally posted by AyushJ:

Does it happen on particular site or all sites?


Just tried it on a couple of .de and .com sites, so I think it happens everywhere... but only with the google and babelfish engine... well and it's not so bad, I just increased the height of the window in your script, that way the scrollbar always appears way below the translation.

1. July 2007, 11:52:39

Schneemann

Rübennase

Posts: 1136

Hmm.. it would be cool to see translations in a panel, so they do not hide the website. In a panel there would also be more space for multi-language translations, maybe even a small wiki / encyclopedia lookup!
It doesn't even have to be a "translation panel", it could instead be a large tooltip that covers whatever panel is currently open. That would be even better, because I usually have the mail or notes panel open..
Well, I have the suspicion this is impossible with userJS.. but maybe something similar.
Search Engines Sharing Thread - your js-based commandline
Usability Forum - Studying the design of everyday things
Page grouping - a compilation
Suffix Search - search keyword typed after the search string

Forums » General Opera topics » User JavaScript