;Language Translator
;Version 1.00
;by LemonButt (lemonbutt@graffiti.net)


On *:Sockopen:LT: {
  Sockwrite -tn $Sockname GET $+(http://www.babelfish.altavista.com/tr?lp=,%~~lt.language,&trtext=,%~~lt.text,) HTTP/1.1
  Sockwrite -tn $Sockname Host: babelfish.altavista.com $+ $Str($Crlf,2)
  Sockwrite -tn $Sockname User-Agent: mIRC
  Sockwrite -tn $Sockname $Crlf
  Unset %~~lt.language
  Unset %~~lt.text
}
On *:Sockread:LT: {
  If ($Sockerr) { Sockclose $Sockname | Echo -a 3* 7[3Info7]3: E' accaduto un errore: $Sockerr | Halt }
  Elseif (%~~tbsitu.updated == $Null) {
    Sockread %~~lt.sockread
    If (*<td bgcolor=white class=s><div style=padding:10px;>* Iswm %~~lt.sockread) && ($Dialog(LT) != $Null) {
      Set %~~lt.settings $Gettok(%~~lt.settings,1-2,32) $Calc($Gettok(%~~lt.settings,3,32) + 1)
      Did -ra LT 105 $Gettok($Gettok(%~~lt.sockread,3,60),2,62) 
      Did -ra LT 110 Total Messages Translated: $Gettok(%~~lt.settings,3,32)
    }
  }
  Unset %~~lt.sockread
}
On *:Load: { Set %~~lt.settings 3 4 0 }
On *:Unload: { Unset %~~lt.* }
Dialog LT {
  Title "Language Translator [/lt]"
  Size -1 -1 205 110
  Option DBU

  Box "Fonte", 100, 5 5 195 40
  Combo 101, 10 14 50 10, Drop
  Edit "", 102, 65 14 130 25, Multi, AutoVS
  Box "Traduzione", 103, 5 50 195 40
  Combo 104, 10 59 50 10, Drop
  Edit "", 105, 65 59 130 25, Multi, AutoVS
  Button "Traduci", 106, 10 29 50 10, OK
  Button "Scambia Linue", 107, 10 74 50 10
  Button "Info", 108, 115 95 40 10
  Button "Chiudi", 109, 160 95 40 10
  Text "", 110, 5 96 110 10
}
On *:Dialog:LT:*:*: {
  If ($Devent == Init) {
    if (%unome == 1) {
      dll dlls/mdx/mdx.dll SetMircVersion $version
      dll dlls/mdx/mdx.dll MarkDialog $dname
      dll dlls/mdx/mdx.dll SetColor $dname 100,103 background $rgb(255,134,0)
      dll dlls/mdx/mdx.dll SetDialog $dname bgcolor $rgb(0,72,170)
      dll dlls/mdx/mdx.dll SetColor 101,102,104,105 background $dname bgcolor $rgb(0,0,0)
      dll dlls/mdx/mdx.dll SetColor 101,102,104,105 textbg $dname bgcolor $rgb(0,0,0)
      dll dlls/mdx/mdx.dll SetColor 101,102,104,105,110 text $rgb(255,255,255)
      /dll dlls\mdx\mdx.dll SetColor $dname 106,107,108,109,110  background $rgb(0,72,170)
      /dll dlls\mdx\mdx.dll SetColor $dname 106,107,108,109,110  textbg $rgb(0,72,170)
    }
    if (%unome == 2) {
      dll dlls/mdx/mdx.dll SetMircVersion $version
      dll dlls/mdx/mdx.dll MarkDialog $dname
      dll dlls/mdx/mdx.dll SetColor $dname 100,103 background $rgb(196,196,196)
      dll dlls/mdx/mdx.dll SetDialog $dname bgcolor $rgb(0,0,95)
      dll dlls/mdx/mdx.dll SetColor 101,102,104,105 background $dname bgcolor $rgb(0,0,0)
      dll dlls/mdx/mdx.dll SetColor 101,102,104,105 textbg $dname bgcolor $rgb(0,0,0)
      dll dlls/mdx/mdx.dll SetColor 101,102,104,105,110 text $rgb(255,255,255)
      /dll dlls\mdx\mdx.dll SetColor $dname 106,107,108,109,110  background $rgb(0,0,95)
      /dll dlls\mdx\mdx.dll SetColor $dname 106,107,108,109,110  textbg $rgb(0,0,95)
    }
    Set -u0 %~~lt.init 1
    While ($LT.Language(%~~lt.init) != $Null) { Did -a $Dname 101,104 $LT.Language(%~~lt.init) | Inc %~~lt.init }
    Did -c $Dname 101 $Gettok(%~~lt.settings,1,32)
    Did -c $Dname 104 $Gettok(%~~lt.settings,2,32)
    Did -ra $Dname 110 Total Messages Translated: $Gettok(%~~lt.settings,3,32)
    Did -f $Dname 106 
  }
  If ($Devent == Sclick) {
    If ($Did == 106) {
      If ($Did($Dname,101).sel != $Did($Dname,104).sel) && ($Did($Dname,102) != $Null) { LT.Translate $+($LT.Language($Did($Dname,101).seltext),_,$LT.Language($Did($Dname,104).seltext)) $Did($Dname,102) }
      ElseIf ($Did($Dname,102) == $Null) { LT $Input(Please enter text to translate.,wdo,Enter Text) }
      Else { LT $Input(Please select two different languages.,wdo,Same Language) }
      Haltdef
    }
    If ($Did == 107) { Set -u0 %~~lt.source $Did($Dname,101).sel | Did -c $Dname 101 $Did($Dname,104).sel | Did -c $Dname 104 %~~lt.source }    
    If ($Did == 108) { LT $Input($+(Language Translator,$Crlf,Version 1.00,$Crlf,by LemonButt (lemonbutt@graffiti.net)),ido,About) }
    If ($Did == 109) { Dialog -x $Dname }
  }
}
Alias LT { 
  If ($1 == $Null) {
    If ($Dialog(LT) == $Null) { Dialog -m LT LT |  if ( %cc181p == on ) { $tunder TDDialog $dialog(LT).hwnd > 2 } }
    Else { Dialog -v LT }
  }
}
Alias -l LT.Translate { 
  Sockclose LT
  Set %~~lt.language $$1
  Set %~~lt.text $Replace($$2-,$Chr(32),$+($Chr(37),20))
  Set %~~lt.settings $Did(LT,101).sel $Did(LT,104).sel $Gettok(%~~lt.settings,3,32)
  Sockopen LT babelfish.altavista.com 80 
}
Alias -l LT.Language {
  If ($$1 == English) { Return en }
  ElseIf ($$1 == Chinese) { Return zh }
  ElseIf ($$1 == Dutch) { Return nl }
  ElseIf ($$1 == French) { Return fr }
  ElseIf ($$1 == German) { Return de }
  ElseIf ($$1 == Greek) { Return el }
  ElseIf ($$1 == Italian) { Return it }
  ElseIf ($$1 == Japanese) { Return ja }
  ElseIf ($$1 == Korean) { Return ko }
  ElseIf ($$1 == Portuguese) { Return pt }
  ElseIf ($$1 == Russian) { Return ru }
  ElseIf ($$1 == Spanish) { Return es }
  ElseIf ($$1 == 1) || ($$1 == zh) { Return Chinese }
  ElseIf ($$1 == 2) || ($$1 == nl) { Return Dutch }
  ElseIf ($$1 == 3) || ($$1 == en) { Return English }
  ElseIf ($$1 == 4) || ($$1 == fr) { Return French }
  ElseIf ($$1 == 5) || ($$1 == de) { Return German }
  ElseIf ($$1 == 6) || ($$1 == el) { Return Greek }
  ElseIf ($$1 == 7) || ($$1 == it) { Return Italian }
  ElseIf ($$1 == 8) || ($$1 == ja) { Return Japanese }
  ElseIf ($$1 == 9) || ($$1 == ko) { Return Korean }
  ElseIf ($$1 == 10) || ($$1 == pt) { Return Portuguese }
  ElseIf ($$1 == 11) || ($$1 == ru) { Return Russian }
  ElseIf ($$1 == 12) || ($$1 == es) { Return Spanish }
}
