Google Translator

By Ryan1981 on Jan 09, 2009

After finding mountaindew's translator working with mIRC I was determined to get google translate to work with mIRC. I found another script on swiftirc wich performed very well using binvars. Since then I have modified the script so it works without problems. After mIRC got an update to allow longer lines I was able to remove the binvars and replace them by normal regexes.

The Result is a Google Translator fully functional with support for 35 languages and auto recognize function. Read comments in script for usage.

Updated to work with the new google translate.

Image

;Google Translator. Compatible with mIRC 6.32+
;To install just load GoogleTranslator.mrc in the remote section of the scripteditor.
;Usage: In a channel type: !translate auto|EN Your non EN (english) sentence here.
;The from|to syntax is composed of 2 languages and a seperator. The first language is the language you
;write in, or autodetect mode. (eg.auto; FR (french) DE (German)). The languages are seperated by a |
;e.g. auto|EN. And the last language is the language it needs to be translated too.
;When Installed try this example first to see what it does. The sentence says "This is a test" in dutch.
;If you use it, the translator should return it in english.
;Example sentence: !translate NL|EN Dit is een test
;Replace NL by auto to let google detect the language.
;Credits for the basics go to seroyez. I removed the binvars and used regexes instead, since mirc 6.32.
;Feel free to use this script in any way you like but remember you can flood google with it so use wiseley.
;I'd like to see someone take this script and make some pretty dialog boxes for it and stuff.
;To get a list of all currently available languages use the command !translang in channel.

ON *:TEXT:*:#: {
  if ($1 == !translate) {
    .remotetranslate # $nick $2-
  }
  elseif ($1 == !translang) {
    .msg # Languages Supported: 1Autorecognize Language - AUTO 2Arabic - AR 1Bulgarian - BG 2Catalan - CA 1Tradiditonal 2Chinese - zh-TW 1Simplified Chinese - zh-CN 2Danish - DA 1German - DE 2English - EN 1Finnish - FI 2French - FR 1Greek - EL 2Hebrew - IW 1Hindi - HI 2Indonesian - ID 1Italian - IT 2Japanese - JA 1Korean - KO 2Croatian - HR 1Latvian - LV 2Croatian - LT 1Dutch - NL 2Norwegian - NO 1Ukrainian - UK 2Polish - PL 1Portuguese - PT 2Romanian - RO 1Russian - RU 2Serbian - SR 1Slovak - SK 2Slovene - SL 1Spanish - ES 2Tagalog - tl 1Czech - CS 2Vietnamese - VI 1Swedish - SV 
  }
}
ON *:INPUT:#: {
  if ($1 == !translate) {
    .remotetranslate # $nick $2-
  }
  elseif ($1 == !translang) {
    .echo # Languages Supported: 1Autorecognize Language - AUTO 2Arabic - AR 1Bulgarian - BG 2Catalan - CA 1Tradiditonal 2Chinese - zh-TW 1Simplified Chinese - zh-CN 2Danish - DA 1German - DE 2English - EN 1Finnish - FI 2French - FR 1Greek - EL 2Hebrew - IW 1Hindi - HI 2Indonesian - ID 1Italian - IT 2Japanese - JA 1Korean - KO 2Croatian - HR 1Latvian - LV 2Croatian - LT 1Dutch - NL 2Norwegian - NO 1Ukrainian - UK 2Polish - PL 1Portuguese - PT 2Romanian - RO 1Russian - RU 2Serbian - SR 1Slovak - SK 2Slovene - SL 1Spanish - ES 2Tagalog - tl 1Czech - CS 2Vietnamese - VI 1Swedish - SV 
  }
}
alias remotetranslate { 
  var %I = $ticks 
  set $+(%,trans.chan.,%I) $1 
  set $+(%,trans.nick.,%I) $2
  set $+(%,trans.lang.,%I) $3 
  set $+(%,trans.phrase.,%I) $remove($4-,$chr(42))
  sockopen $+(remotetrans.,%I) translate.google.com 80  
} 
on *:SOCKOPEN:remotetrans.*: { 
  sockwrite -n $sockname GET $+(/translate_t?langpair=,$($+(%,trans.lang.,$gettok($sockname,2,46)),2),&text=,$urlencode($($+(%,trans.phrase.,$gettok($sockname,2,46)),2))) HTTP/1.1 
  sockwrite -n $sockname Host: translate.google.com 
  sockwrite -n $sockname User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9b4) Gecko/2008030714 Firefox/3.0b4 $+ $crlf $+ $crlf 
} 
on *:SOCKREAD:remotetrans.*: {
  var %I = $gettok($sockname,2,46)
  var %r 
  sockread %r
  if ($regex(%r,<textarea name=utrans wrap=SOFT dir="ltr" id=suggestion style="width:80%;margin:5px 0;overflow:auto">)) {
    .msg $($+(%,trans.chan.,%I),2) 4Translation from $($+(%,trans.nick.,%I),2) :2 $replace($regsubex(%r,/[^*]*<textarea name=utrans wrap=SOFT dir="ltr" id=suggestion style="width:80%;margin:5px 0;overflow:auto">|</textarea>[^*]*/g,$null),&#39;,') 
    .echo $($+(%,trans.chan.,%I),2) 4Translation from $($+(%,trans.nick.,%I),2) :2 $replace($regsubex(%r/[^*]*<textarea name=utrans wrap=SOFT dir="ltr" id=suggestion style="width:80%;margin:5px 0;overflow:auto">|</textarea>[^*]*/g,$null),&#39;,') 
    unset %trans.*. [ $+ [ $gettok($sockname,2,46) ] ] | sockclose $sockname
  }
  elseif ($regex(%r,<textarea name=utrans wrap=SOFT dir="rtl" id=suggestion style="width:80%;margin:5px 0;overflow:auto">)) {
    .msg $($+(%,trans.chan.,%I),2) 4Translation from $($+(%,trans.nick.,%I),2) :2 $replace($regsubex(%r,/[^*]*<textarea name=utrans wrap=SOFT dir="rtl" id=suggestion style="width:80%;margin:5px 0;overflow:auto">|</textarea>[^*]*/g,$null),&#39;,') 
    .echo $($+(%,trans.chan.,%I),2) 4Translation from $($+(%,trans.nick.,%I),2) :2 $replace($regsubex(%r,/[^*]*<textarea name=utrans wrap=SOFT dir="rtl" id=suggestion style="width:80%;margin:5px 0;overflow:auto">|</textarea>[^*]*/g,$null),&#39;,') 
    unset %trans.*. [ $+ [ $gettok($sockname,2,46) ] ] | sockclose $sockname
  }
}
alias langfull { 
  if ($1 == Auto) { return Auto }
  elseif ($1 == ar) { return Arabic }
  elseif ($1 == bg) { return Bulgarian }
  elseif ($1 == ca) { return Catalan }
  elseif ($1 == zh-TW) { return Tradiditonal Chinese }
  elseif ($1 == zh-CN) { return Simplified Chinese }
  elseif ($1 == da) { return Danish }
  elseif ($1 == de) { return German }
  elseif ($1 == en) { return English }
  elseif ($1 == fi) { return Finnish }
  elseif ($1 == fr) { return French }
  elseif ($1 == el) { return Greek }
  elseif ($1 == iw) { return Hebrew }
  elseif ($1 == hi) { return Hindi }
  elseif ($1 == id) { return Indonesian }
  elseif ($1 == it) { return Italian }
  elseif ($1 == ja) { return Japanese }
  elseif ($1 == ko) { return Korean }
  elseif ($1 == hr) { return Croatian }
  elseif ($1 == lv) { return Latvian }
  elseif ($1 == lt) { return Croatian }
  elseif ($1 == nl) { return Dutch }
  elseif ($1 == no) { return Norwegian }
  elseif ($1 == uk) { return Ukrainian }
  elseif ($1 == pl) { return Polish }
  elseif ($1 == pt) { return Portuguese }
  elseif ($1 == ro) { return Romanian }
  elseif ($1 == ru) { return Russian }
  elseif ($1 == sr) { return Serbian }
  elseif ($1 == sk) { return Slovak }
  elseif ($1 == sl) { return Slovene }
  elseif ($1 == es) { return Spanish }
  elseif ($1 == tl) { return Tagalog }
  elseif ($1 == cs) { return Czech }
  elseif ($1 == vi) { return Vietnamese }
  elseif ($1 == sv) { return Swedish }
} 
alias b { return $+($chr(2),$1-,$chr(2)) } 
alias br { return $+($chr(40),$1-,$chr(41)) } 
alias urlencode { return $regsubex($1,/(\W)/gS,% $+ $base($asc(\1),10,16,2))) } 
alias antientities { return $regsubex($1,/&(.+?);/g,$entity2chr(\1)) } 
alias entity2chr { 
  if #* iswm $1 return $chr($mid($1,2)) 
  elseif $1 == nbps return $chr(32) 
  elseif $1 == quot return " 
  elseif $1 == apos return ' 
  elseif $1 == amp return & 
  elseif $1 == lt return < 
  elseif $1 == gt return > 
  elseif $1 == copy return © 
  elseif $1 == reg return ® 
  else return $1 
} 

Comments

Sign in to comment.
Serpentsounds   -  Nov 18, 2010

I hate to plug, but the one on my profile still works fine for me (albeit the snippet itself being outdated) if you need fixing notes. I'd recommend using the google translator API rather than translate.google.com.

 Respond  
  -  Nov 17, 2010

dose not work!! anyone works with right now ??

 Respond  
Raicho Ichisada   -  Sep 16, 2010

eh not works now

 Respond  
bourneident   -  Aug 22, 2010

seems to work for the most part but can't seem to get rid of * Invalid parameters: $regsubex (line 51, translator.mrc) any thoughts using mirc 7.1

 Respond  
Ryan1981   -  Jun 21, 2010

I updated it to work with the current google translate. Good luck with it.

 Respond  
Ryan1981   -  Jun 10, 2010

Hi all, it was recently brought to my attention that the translator wasn't working anymore and this is indeed because google changed something. When I check the debug I get:

HTTP/1.1 301 Moved Permanently
Date: Thu, 10 Jun 2010 20:22:04 GMT
Expires: Thu, 10 Jun 2010 20:22:04 GMT
Cache-Control: private, max-age=86400
Location: http://translate.google.com/?langpair=auto%7Cen&text=This+is+a+test

I don't know yet how to fix it and I am extremely busy so I can't promise anything but hopefully some smart person here can give a fix with this info :D

 Respond  
ink   -  Jan 03, 2010

maybe it doesn´t work anymore coz google changed the script...
this part changed and you can´t find it anymore in the website of google translator

i have no idea of scripting but it would be nice if someone would make a new one, an update!
 Respond  
Pangaea   -  Dec 25, 2009

hello again.
dosent seem to be my day with scripts
this is yet another that aint workin

<PanAway> !translale auto|fr hello world <PanAway> !translate auto|EN this is a test
<PanAway> !translate auto|EN this is a test <PanAway> !translate auto|de this is a test

nada

also u mentioned "auto mode".. i see no menu or dialoug for this script

dose this still work?
after loading it in remotes, how do i turn it on?
where and how do i access the options dialoug?

regards
pan

 Respond  
Johnbrandon   -  Nov 21, 2009

the script does not work anymore for some reason.

 Respond  
,eh   -  Sep 22, 2009

This would be perfect if only the translated text would be seen by the other party.

So if "!translate EN:NL test" is written, it will not appear in the channel, but the translated text will appear.. Now that would be real translation! :D

 Respond  
RicJames   -  Sep 08, 2009

A lot of the sentences i try to translate don't work. e.g: !translate en|es Hello people comes out the same.

 Respond  
ataraxia   -  Mar 24, 2009

In the case of mIRC scripting, which is going to run slower than a fat bitch up a flight of stairs, there's only so much difference that using a replace instead of a bunch of if's will make.

 Respond  
tzar469   -  Mar 23, 2009

I'd use $& to break up the line into manageable chunks. Readability must often be sacrificed for better code :P

 Respond  
ataraxia   -  Mar 22, 2009

While yes, you can shorten the code in that fashion, you'd have a single, long, hard to read, and hard to edit line. As the code stands, it's quite readable and editable. :)

 Respond  
tzar469   -  Mar 22, 2009

You can shorten the code by using $replace instead of all those if statements.

 Respond  
Calyp5o   -  Jan 16, 2009

Excellent! xx

 Respond  
Ryan1981   -  Jan 16, 2009

Yes I agree, in fact I have that in my version. But that is made for a non IRC channel. Feel free to add or modify it to your own needs.

 Respond  
Jethro   -  Jan 12, 2009

I think it would be even better without having to type in !translate en|fr

Let's say if there is a custom switch, and I select French as a language to translate, meaning eveytime I type in English, it automatically converts my English into French; Just like you would enter a sentence in a channel naturally.

 Respond  
^Neptune   -  Jan 10, 2009

Incredible what it does for such a short code. Very good job.

 Respond  
uneek   -  Jan 09, 2009

Works great! Thanks for the share.

 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.