Lost password? | Help

[ advanced search ]

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

Forums » Opera Community » General Opera topics » User JavaScript

Go to last post

Wednesday, 7. March 2007, 01:49:56

Stevie1

avatar

Posts: 15

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

Wednesday, 7. March 2007, 02:34:45

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.

Thursday, 8. March 2007, 04:09:26

Stevie1

avatar

Posts: 15

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

Thursday, 8. March 2007, 20:10:18

Stevie1

avatar

Posts: 15

really no possibilty to do that? :frown:

Saturday, 10. March 2007, 09:36:32

AyushJ

avatar

Posts: 4754

not perfect but here it is-
Google-Translation

--
Ayush

Saturday, 10. March 2007, 10:21:53

AyushJ
How is that supposed to work? I've installed this script, but see no difference.

Saturday, 10. March 2007, 10:32:07

AyushJ

avatar

Posts: 4754

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

Saturday, 10. March 2007, 10:52:05

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!

Saturday, 10. March 2007, 10:58:40

AyushJ

avatar

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..

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

Stevie1

avatar

Posts: 15

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?

Monday, 12. March 2007, 14:13:27

AyushJ

avatar

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.

Wednesday, 14. March 2007, 02:33:28

Stevie1

avatar

Posts: 15

from what i read in the german opera forum (www.opera-info.de) theres no possibilty to
catch a word without selecting it :frown:
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?

Monday, 19. March 2007, 13:40:08

My google-translate.js for using from menu (on cross-document messaging).

Friday, 30. March 2007, 04:44:47

addps4cat

avatar

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?

Friday, 30. March 2007, 14:00:30

addps4cat

avatar

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.

Friday, 30. March 2007, 16:04:49

AyushJ

avatar

Posts: 4754

ok. fixed it(charset problem). redownload the script.

Google Translation in tooltip

Friday, 30. March 2007, 17:36:39

addps4cat

avatar

Posts: 4

Sweet, thanks a million. Worked like a charm.

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

FiSz

avatar

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

Tuesday, 24. April 2007, 14:46:58

Grrblt

avatar

Posts: 31

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.

Tuesday, 24. April 2007, 15:09:24

AyushJ

avatar

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. :frown:

Thursday, 3. May 2007, 05:52:55

kinnik

avatar

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

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

AyushJ

avatar

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

Thursday, 3. May 2007, 13:32:21

igzist

avatar

Posts: 47

Thanks AyushJ

Really nice Js.

Friday, 4. May 2007, 01:55:19

kinnik

avatar

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

Friday, 4. May 2007, 05:54:34

AyushJ

avatar

Posts: 4754

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

Wednesday, 9. May 2007, 10:26:01

Grrblt

avatar

Posts: 31

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. :frown:


Any way around it?

Wednesday, 9. May 2007, 13:34:30

AyushJ

avatar

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

Wednesday, 9. May 2007, 15:34:23

Grrblt

avatar

Posts: 31

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

Wednesday, 9. May 2007, 15:55:42

AyushJ

avatar

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

Wednesday, 9. May 2007, 16:30:51

Grrblt

avatar

Posts: 31

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

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

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

AyushJ

avatar

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*':'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.

Wednesday, 9. May 2007, 18:36:41

Grrblt

avatar

Posts: 31

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.

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

AyushJ

avatar

Posts: 4754

Originally posted by Grrblt:

Any chance of getting that button in the corner back?



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

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

Thursday, 10. May 2007, 22:43:43

addps4cat

avatar

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?

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

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 :frown: ) 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?

Monday, 14. May 2007, 01:09:36

AyushJ

avatar

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

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

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:

Tuesday, 15. May 2007, 11:08:50

AyushJ

avatar

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:

...
URL:"http://babelfish.altavista.com/tr?trtext=%T&lp=%FROM_%TO"
}


,'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"
}

}




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...

Tuesday, 15. May 2007, 21:42:11

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

Wednesday, 16. May 2007, 11:42:43

AyushJ

avatar

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 ??

Wednesday, 16. May 2007, 12:30:54

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

Wednesday, 16. May 2007, 15:05:11

HaJotKE

Grumbling Hyper-Critical Cantankerous Curmudgeon!

avatar

Banned User

Germany

[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! :frown:

Tried it several times...

Wednesday, 16. May 2007, 16:52:46

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.

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

AyushJ

avatar

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

Wednesday, 16. May 2007, 20:22:47

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...

Wednesday, 16. May 2007, 21:10:44

HaJotKE

Grumbling Hyper-Critical Cantankerous Curmudgeon!

avatar

Banned User

Germany

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! :frown:

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

AyushJ

avatar

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 !!

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

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.

Sunday, 1. July 2007, 11:52:39

Schneemann

Rübennase

avatar

Posts: 1135

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.

Forums » Opera Community » General Opera topics » User JavaScript