Easy Google Translator

By FordLawnmower on Apr 18, 2009

This is a basic version of the translator that I made for my own use. This translator is unique because I made it to translate from the clipboard as well as translate directly to the channel/query. I got bored and changed this to Google. I got rid of all the messy popups and added mini dialogs to replace them. There are now 4 ways to use this Translator. See the notes at the top of the script for how to.
Added
Trigger for bots.
To use just right click - click google translator - then click trigger and On
Syntax is !trans L1-L2 Text to translate. or @trans L1-L2 Text to translate.
Example !trans en-de test text here.
The !trans trigger will notice the user and the @trans trigger will message the channel, provided the user has half op or higher.
Image

;***
;***
;Easy mIRC Translator by Ford_Lawnmower irc.GeekShed.net #Script-Help
;This script gets a translation from Google Translator
;There are 4 options for how to use this translator
;1.) Basic Bot trigger w/on|off switch. Syntax: !trans L1-L2 text or !trans L1_L2 text. Result: Sent to the channel.
;2.) Send to Channel/Query Dialog - Select languages, enter text. Result: Sent to Active Channel/Query | echo to Status.
;3.) Translate Clipboard Contents Dialog - Copy text to clipboard,Click translate. Result: Echo to active screen.
;4.) Use Dialogs - Select languages,Enter text,Select destination,Click translate. Result: Your choice.
;Translates 28 languages. All translations come from Google,therefore the accuracy has nothing to do with this script.
;***
;***
#TransTrigger off
On $*:Text:/^(!|@)trans.*/Si:#: {
  if ($timer($+(Gtrans,$network,$nick))) { return }
  .timer $+ $+(Gtrans,$network,$nick) 1 4 noop
  var %method $iif($regml(1) == !,.notice $nick,$iif($regex($nick($chan,$nick).pnick,/(!|~|&|@|%)/),.msg $chan,.notice $nick))
  if (help isin $1) { TransHelp %method | return }
  if (!$3) { %method No text to Translate | TransHelp %method | return }
  if (!$regex($left($2,3),/-|_/)) { %method $2- is unknown to me. | TransHelp %method | return }
  if (!$regex($left($2,2),/en|fr|nl|ru|de|pt|it|es|sq|et|ca|hr|cs|da|et|tl|fi|gl|hu|id|lv|lt|mt|no|pl|ro|sk|sl|sv|tr/i)) {
    %method $2- is unknown to me.
    TransHelp %method
    return
  }
  if (!$regex($right($2,2),/en|fr|nl|ru|de|pt|it|es|sq|et|ca|hr|cs|da|et|tl|fi|gl|hu|id|lv|lt|mt|no|pl|ro|sk|sl|sv|tr/i)) {
    %method $2- is unknown to me.
    TransHelp %method
    return
  }
  trans %method $2 $strip($3-)
}
#TransTrigger end
alias -l TransHelp {
  $1-2 Syntax: !trans L1-L2 Text to translate. L1 = the language you are typing in. L2 = The language you want to translate to.
  $1-2 Valid languages: en,fr,nl,ru,de,pt,it,es,sq,et,ca,hr,cs,da,et,tl,fi,gl,hu,id,lv,lt,mt,no,pl,ro,sk,sl,sv,tr $&
    For a code explanation look here -->> http://code.google.com/apis/ajaxlanguage/documentation/reference.html#LangNameArray
}
alias -l trans {
  var %sockname $+(GTrans,$network,$2,$ticks)
  sockopen %sockname translate.google.com 80
  sockmark %sockname $1-2 $+(/translate_t?langpair=,$lower($replace($3,-,|,_,|)),&ie=UTF-8&oe=UTF-8&text=,$fixurl($4-),#)

}
on *:sockopen:GTrans*: {
  if (!$sockerr) {
    sockwrite -nt $sockname GET $gettok($sock($sockname).mark,3,32) HTTP/1.0
    sockwrite -n $sockname Host: translate.google.com $+ $str($CRLF,2)
  }
  else { echo -st socket error $nopath($script) | sockclose $sockname | return }
}
on *:sockread:GTrans*: {
  if ($sockerr) { echo -st socket error $nopath($script) | sockclose $sockname | return }
  else {
    sockread -fn &transvar
    var %counter 1, %result
    while ($bintween(&transvar,onmouseout="this.style.backgroundColor='#fff'">,</span>,%counter)) {
      %result = $+(%result,$chr(32),$v1)
      inc %counter
    }
    if ($bintween(&transvar,onmouseout="this.style.backgroundColor='#fff'">,</span>,1)) {
      $gettok($sock($sockname).mark,1-2,32) $fixhtml(%result)
    }
  }
}
alias -l bintween {
  var %count = 1, %mark = 0, %mark2 = 0
  while (%count <= $4) {
    if ($bfind($1, %mark2, $2).text) {
      %mark = $calc($bfind($1, %mark2, $2).text + $len($2))
      if ($bfind($1, %mark, $3).text) {
        %mark2 = $bfind($1, %mark, $3).text
      }
      else { return 0 } 
    }
    else { return 0 }
    inc %count
  }
  return $bvar($1, $iif(%mark > 0,%mark,1), $calc(%mark2 - %mark)).text
}
alias -l inputencode { return $regsubex($strip($1-),/([^a-z0-9])/ig,% $+ $base($asc(\t),10,16,2)) }
alias -l fixhtml { return $remove($regsubex($1-,/#([\d][\d][\d]?);/g,$chr(\t)),&amp;,gt;,lt;) }
ON *:Start:{
  Echo -a 4 6You have just loaded 3F4o5r6d7-9T3r4a5n6s7l9a3t4o5r 4 6English Version.
  Echo -a 4 6By Ford_Lawnmower
  Echo -a 4 6Questions and comments,  You can find me in #Script-Help on irc.geekshed.net
  Echo -a 4 6irc://irc.geekshed.net
}
dialog Translate {
  title "Ford-Trans Basic"
  size -1 -1 152 137
  option dbu
  combo 1, 8 8 60 10, drop
  combo 2, 84 8 60 10, drop
  edit "", 3, 8 32 136 82, multi autovs rich
  button "Translate", 5, 56 115 38 12
  combo 6, 84 21 60 10, drop
  button "Close", 7, 104 115 38 12, cancel
  button "Clear Screen", 8, 10 115 37 12
  text "To", 9, 70 10 9 8, center
  text "Translate this text to ------->", 10, 6 22 73 8, right
  text "", 11, -2 128 153 8, center
}
On *:Dialog:Translate:Sclick:8: {
  did -rf $dname 3
}
On *:Dialog:Translate:Sclick:5: {
  if (!$did($dname,3).text) { 
    did -a $dname 11 Type some text in the box to translate
    did -f $dname 3
    .timer 1 3 did -a $dname 11
    return
  }
  var %trans.text, %trans.lines = $did($dname,3).lines, %trans.count = 1
  while (%trans.count <= %trans.lines) {
    %trans.text = %trans.text $+ $did($dname,3,%trans.count).text
    inc %trans.count
  }
  if ($did($dname,6).seltext == Echo Here) {
    trans echo -a $langcode($+($did($dname,1).seltext,_,$did($dname,2).seltext)) %trans.text
  }
  else {
    var %tlanguages = $langcode($+($did($dname,1).seltext,|,$did($dname,2).seltext))
    trans msg $did($dname,6).seltext %tlanguages %trans.text    
  }
}
On *:Dialog:Translate:init:*: {
  didtok $dname 1,2 44 English,German,Italian,Russian,Spanish,Portuguese,French,Dutch,Albanian,Estonian,Catalan,Croatian,Czech,Danish,Estonian,Filipino
  didtok $dname 1,2 44 Galician,Hungarian,Indonesian,Latvian,Lithuanian,Maltese,Norwegian,Polish,Romanian,Slovak,Slovenian,Swedish,Turkish
  did -c $dname 1 1
  did -c $dname 2 2
  did -ac $dname 6 Echo Here
  if ($chan(0)) {
    var %chan.count = $chan(0)
    while %chan.count {
      did -a $dname 6 $chan(%chan.count)
      dec %chan.count
    }
  }
  if ($query(0)) {
    var %pm.count = $query(0)
    while (%pm.count) {
      did -a $dname 6 $query(%pm.count)
      dec %pm.count
    }
  }
}
alias Trans_Chan {
  if ($dialog(Trans_Chan)) { dialog -v Trans_Chan Trans_Chan }
  else { dialog -m Trans_Chan Trans_Chan }
}
dialog Trans_Chan {
  title "Translate to Channel/Query"
  size -1 -1 136 48
  option dbu
  combo 1, 0 0 60 10, drop
  combo 2, 76 0 60 10, drop
  text "To", 3, 64 2 9 8
  edit "", 4, 0 15 135 10, autohs
  button "Clear", 5, 2 32 37 12
  button "Send", 6, 50 32 37 12
  button "Cancel", 7, 96 32 37 12, cancel
}
On *:Dialog:Trans_Chan:Sclick:6: {
  if (!$did($dname,4).text) { did -f $dname 4 | return }
  else {
    var %tlanguages = $langcode($+($did($dname,1).seltext,|,$did($dname,2).seltext))
    if ($active == status window) { trans echo -a %tlanguages $did($dname,4).text }
    else { trans msg $active %tlanguages $did($dname,4).text }
  }
}
On *:Dialog:Trans_Chan:Sclick:5: { did -rf Trans_Chan 4 }
On *:Dialog:Trans_Chan:init:*: {
  didtok $dname 1,2 44 English,German,Italian,Russian,Spanish,Portuguese,French,Dutch,Albanian,Estonian,Catalan,Croatian,Czech,Danish,Estonian,Filipino
  didtok $dname 1,2 44 Galician,Hungarian,Indonesian,Latvian,Lithuanian,Maltese,Norwegian,Polish,Romanian,Slovak,Slovenian,Swedish,Turkish
  did -c $dname 1 1
  did -c $dname 2 2
  did -f $dname 4
}
dialog ClipTrans {
  title "ClipTrans"
  size -1 -1 64 48
  option dbu
  combo 1, 1 0 63 10, drop
  combo 2, 1 20 63 10, drop
  text "To", 3, 24 11 9 8, center
  button "Translate", 4, 1 34 29 12
  button "Close", 5, 34 34 29 12, cancel
}
alias -l ClipTrans {
  if ($dialog(Cliptrans)) { dialog -v Cliptrans Cliptrans }
  else { dialog -m Cliptrans Cliptrans }
}
On *:Dialog:ClipTrans:Sclick:4: {
  var %tlanguages = $langcode($+($did($dname,1).seltext,|,$did($dname,2).seltext)) 
  if ($cb(0)) { TransClip %tlanguages }
  else { echo -a clipboard is empty }
}
On *:Dialog:ClipTrans:init:*: {
  didtok $dname 1,2 44 English,German,Italian,Russian,Spanish,Portuguese,French,Dutch,Albanian,Estonian,Catalan,Croatian,Czech,Danish,Estonian,Filipino
  didtok $dname 1,2 44 Galician,Hungarian,Indonesian,Latvian,Lithuanian,Maltese,Norwegian,Polish,Romanian,Slovak,Slovenian,Swedish,Turkish
  did -c $dname 1 2
  did -c $dname 2 1
}
alias -l httpstrip {
  var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x,&nbsp;,&#039;,&#039 ;)
  return %x
}
alias  -l fixurl return $regsubex($utfdecode($utfencode($1-)),/([^a-z0-9\.])/ig,% $+ $base($asc(\t),10,16,2))
alias -l transclip { 
  var %clip.count = $cb(0), %clip.counter = 1, %clip.time = 1
  while (%clip.counter <= %clip.count) {
    .timer 1 %clip.time trans echo -a $1 $remove($strip($cb(%clip.counter)),$chr(124))
    inc %clip.counter
    inc %clip.time 2
  }
}
alias -l Ford-Trans {
  if (!$dialog(Translate)) { dialog -m translate translate }
  else { dialog -v translate translate }
}
alias -l langcode { 
  var %langcode = $replace($1,english,en,german,de,italian,it,spanish,es,portuguese,pt,french,fr,dutch,nl,albanian,sq,estonian,et,catalan,ca,croatian,hr,czech,cs,$&
    danish,da,estonian,et,filipino,tl,finnish,fi,galician,gl,hungarian,hu,indonesian,id,latvian,lv,lithuanian,lt,maltese,mt,norwegian,no,polish,pl,romanian,ro,slovak,sk,$&
    slovenian,sl,swedish,sv,turkish,tr,russian,ru) 
  return %langcode
}
;****** End of Script....Start of Popups *******
menu channel,status,menubar {
  -
  Utilities
  .Google Translator
  ..Send to Channel/Query:Trans_Chan
  ..Translate Clipboard Contents:ClipTrans
  ..Use Dialogs:Ford-Trans
  ..$iif($group(#TransTrigger) == On,$style(1)) TransTrigger
  ...$iif($group(#TransTrigger) == On,$style(2)) On: .enable #TransTrigger
  ...$iif($group(#TransTrigger) == Off,$style(2)) Off: .disable #TransTrigger
  -
}

Comments

Sign in to comment.
davehorse   -  Feb 02, 2011

thanks :)

 Respond  
Kingc44   -  Jan 12, 2011

@davehorse this other version does what you're looking for
http://www.hawkee.com/snippet/6925/

 Respond  
davehorse   -  Jan 12, 2011

wow im loving this translate script.

Question tho. is it all possible for the script to be auto loading in to a bot and auto translate any text that comes in to the channel and turn it in to English and post back to channel?

I dont get a lot of it but I would certainly find it very useful

 Respond  
FordLawnmower   -  Jan 09, 2011

Updated djD3F. Thanks for the heads up :)

 Respond  
djD3F   -  Jan 09, 2011

Ford,

Please update your script to work with whatever Google did to break it! TYVM!

 Respond  
The_One_And_Only   -  Nov 30, 2010

it does not seem to work with my mirc (6.35) when i click translate it does nothing, gives no error, no translation, nothing...

 Respond  
Flaco22   -  Nov 29, 2010

Thank you very much for all the help provided here!!
As i am a semi-noob in this, i've chosen to download the last mirc version in the bot, and now it works perfectely well :)

Thank you again!

 Respond  
jaytea   -  Nov 29, 2010

indeed Gummo, but /.echo -q functions as /noop does and is what we used to use back before its introduction :P there was also this form which was common with $regsub():

//var %x, %y = $regsub( ... , %x)

$regsubex() made our lives easier in that respect ;P in this case though, the unique functionality of $regsubex() is required since Ford uses $chr(\t) in the substitution parm. $regsub() does not easily lend itself to being used in this way, which is why $regsubex() was so eagerly requested and wholly welcomed as an addition to 6.17.

 Respond  
blackvenomm666   -  Nov 29, 2010

flaco at least upgrade to v6.32 if not newer im using v6.32 and everything works fine on it

 Respond  
Gummo   -  Nov 29, 2010

/echo -q is an echo which doesn't show up if you put the . in front of your alias call.
/.msg hides the echo of your message.
If you created your own /noop alias which pointed to a silenced (e.g. /.noop2) alias then you could use echo -q but that'd be a pain anyway.
The other alternative, of course, is to just use a dud variable in its place.

 Respond  
Flaco22   -  Nov 29, 2010

oww...i wanted to avoid that! :P
Thank you Jethro_ ^^

 Respond  
Jethro   -  Nov 29, 2010

Perhaps it's about time you upgrade to the latest version, Flaco22.

Your old version doesn't recognize the $regsubex identifier and the noop command. I believe they weren't introduced until the version 6.17.

You version only recognize $regsub and /echo -q in place of those aforementioned ones.

 Respond  
Flaco22   -  Nov 28, 2010
  • No such identifier: $regsubex (line 359, yourscript.ini)
  • No such identifier: $regsubex (line 359, yourscript.ini)
    NOOP Unknown command
  • No such identifier: $regsubex (line 462, yourscript.ini)
    NOOP Unknown command
  • No such identifier: $regsubex (line 462, yourscript.ini)
    NOOP Unknown command
  • No such identifier: $regsubex (line 462, yourscript.ini)
    NOOP Unknown command

Why i keep getting this? i have mirc 6.12
thanks!

 Respond  
FordLawnmower   -  Nov 19, 2010

No problem startmeup. I fixed this one because of your comment :)
I put your edit on the other post.

 Respond  
startmeup   -  Nov 19, 2010

can you believe that I was actually commenting on your OTHER translate snippet? haha..i will ask ya there...thanks!

 Respond  
FordLawnmower   -  Nov 19, 2010

@startmeup I had this script on the BROKEN list. The code at the top of the page is now working.
Please explain a little more what you want the script to do and I will try to help you.

 Respond  
startmeup   -  Nov 19, 2010

Another great lil snippet, does a great job. I am on the bot more often than not and would like to be able to see the translation. Can you help me out on that one?

 Respond  
RicJames   -  Jun 18, 2010

/me feels like such a noob :/ Thanks FLM :)

 Respond  
FordLawnmower   -  Jun 17, 2010

No problem Kingc44 :)

You should have also got this RicJames.

Valid languages: en,fr,nl,de,pt,it,es,sq,et,ca,hr,cs,da,et,tl,fi,gl,hu,id,lv,lt,mt,no,pl,ro,sk,sl,sv,tr For a code explanation look here -->> http://code.google.com/apis/ajaxlanguage/documentation/reference.html#LangNameArray
It's just a syntax error. eng isn't a google language code.
Should be @trans en-de hello

 Respond  
RicJames   -  Jun 17, 2010

This doesn't work for me :( I keep getting the following:

<~me> @trans fr-eng hello
<~bot> fr-eng hello is unknown to me.

<~me> @trans eng-de hello
<~Bot> eng-de hello is unknown to me.

 Respond  
Kingc44   -  Jun 16, 2010

@FordLawnmower, Whoa!! thank you so much FordLawnmower. I really appreciate your response, It works flawlessly now :). Thanks again for your response ;)

 Respond  
FordLawnmower   -  Jun 16, 2010

@kingc44. Well it actually sends the users lower than halfop a notice so you don't see it in the channel. Only the user who asked for the translation will see the result.
If you want to change it, I can give you two ways.
First:
This will make both triggers (!trans & @trans) message the channel.
Find this line in the script. (I have it at line 17)

 var %method $iif($regml(1) == !,.notice $nick,$iif($regex($nick($chan,$nick).pnick,/(!|~|&|@|%)/),.msg $chan,.notice $nick))

Replace it with this line:

var %method .msg $chan

Another way to change it would still allow you to use the !trans trigger to notice the user and the @trigger to message the channel.
To do this:
Find this line in the script. (I have it at line 17)

 var %method $iif($regml(1) == !,.notice $nick,$iif($regex($nick($chan,$nick).pnick,/(!|~|&|@|%)/),.msg $chan,.notice $nick))

Replace it with this line:

var %method $iif($regml(1) == !,.notice $nick,.msg $chan)

I'm glad you like the script and I hope this helps you Kingc44.

 Respond  
Kingc44   -  Jun 16, 2010

I love this translator but I'm having a problem with it. The problem is that it only lets users with op privileges use it. When a regular user tries to translate something it just doesn't work until I give hi/her op privileges. Does anyone know how to fix this?

PS I'm new to scripting, I only know the very basic

thanks in advanced :)

 Respond  
FordLawnmower   -  Apr 18, 2010

Okey, Thanks Jethro_

 Respond  
Jethro   -  Apr 18, 2010

Ford, a user named LaTiNo needs your help with your script at the forum request:

http://www.hawkee.com/phpBB2/viewtopic.php?t=21228

Looks like he tries to translate your script into Spanish and wants it to send translation into channel. I'm not sure, but please have a look if you can.

 Respond  
FordLawnmower   -  Nov 16, 2009

Working fine now :)

 Respond  
FordLawnmower   -  Nov 16, 2009

Allow me to be the first to fix my translator. It seems google has been making a few changes to their translation page.
All fixed :) Thanks to mentok at http://Twizted-Reality.com for the heads up. I wouldn't have noticed for at least a week.

 Respond  
FordLawnmower   -  Sep 05, 2009

o.O
Well if you get it again let me know. It's more than likely just a single character that needs special treatment.

 Respond  
Cheiron   -  Sep 05, 2009

i have noticed that some sentances it wont work on others it will .. as for the text i got the error on .. when i shortened what had been typed .. it translated it.. but the original length it still gave the same error. i cannot paste publicly what had been put that i needed to translate due to its content but suffice to say it had the user zlined as a result. i could private message it to you though if you wish

 Respond  
FordLawnmower   -  Sep 05, 2009

| 11:22 | <Lunch|Box> !trans en-de this is a very long sentence this is a very long sentence this is a very long sentence this is a very long sentence this is a very long sentence this is a very long sentence this is a very long sentence this is a very long sentence this is a very long sentence this is a very long sentence this is a very long sentence this is a very long sentence this is a very long sentence this is a very long sentence this is a very long sentence this is a very long sentence this is a very long sentence this is a very long sentence this is a very long sentence this is a very long sentence this is a very long sentence this is a very long sentence
| 11:22 | -Ford_Lawnmower- >Dies ist ein sehr langer Satz, das ist ein sehr langer Satz, das ist ein sehr langer Satz, das ist ein sehr langer Satz, das ist ein sehr langer Satz, das ist ein sehr langer Satz, das ist ein sehr langer Satz, das ist ein sehr langer Satz ist ein sehr langer Satz, das ist ein sehr langer Satz, das ist ein sehr langer Satz, das ist ein sehr langer Satz, das ist ein sehr langer Satz, das ist ein sehr langer Satz, das ist eine sehr lange
There is probably a correlation here but I don't think it is the line length. I tested the clipboard function for this with 5 pages of text.
Perhaps there is a character there that needs handled differently.
Laughs @ script86.ini
If you paste the text that caused the error I will figure out why it didn't translate. Thanks :)

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.