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.
;***
;***
;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)),&,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, ,',' ;)
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
-
}
@davehorse this other version does what you're looking for
http://www.hawkee.com/snippet/6925/
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.
/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.
Why i keep getting this? i have mirc 6.12
thanks!
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
@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.
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 :)
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.
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.
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
| 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 :)