You can try this script:

Code:
on *:TEXT:!babel *:#:{
  babel $2-
}

alias babel {
  if (!$1) {
    echo -a Syntax: /babel [type] <words to translate here, max 700 chars>
    if (%babelchan) msg %babelchan Syntax: !babel [type] <words to translate here, max 700 chars>
    return
  }

  set %babeltype en_nl
  if ($regex($1,/^[a-z]{2}_[a-z]{2}$/i)) {
    %babeltype = $1
    tokenize 32 $2-
  }

  set %babel $left($1-,700)
  if ($target) set %babelchan $target
  if ($sock(babel)) sockclose babel
  sockopen babel world.altavista.com 80
  if ($sockerr) babelfail
  .timerbabel 1 30 babelfail
}

alias babelfail {
  echo -a Error: Unable to contact Babelfish
  if (%babelchan) msg %babelchan Error: Unable to contact Babelfish
  .timerbabel off
  unset %babel
  sockclose babel
}

on *:SOCKOPEN:babel:{
  if ($sockerr) {
    babelfail
    return
  }
  if (!%babel) {
    sockclose babel
    echo -a Error: No text to translate  
    if (%babelchan) msg %babelchan Error: No text to translate
    return
  }

  var %babelu = %babel
  while ($regex(babel,%babelu,/([^% \w])/Sg)) {
    var %babelu = $replace(%babelu,$regml(babel,1),% $+ $base($asc($regml(babel,1)),10,16))
    if ($calc($len(%babelu) $+ 2) > 800) break
  }

  if (!%babeltype) set %babeltype en_fr
  var %data = doit=done&intl=1&tt=urltext&trtext= $+ $replace(%babelu,$chr(32),+) $+ &lp= $+ %babeltype $+ &btnTrTxt=Translate
  var %write = sockwrite -tn $sockname

  %write POST /tr HTTP/1.1
  %write Referer: http://world.altavista.com/tr
  %write Content-Type: application/x-www-form-urlencoded
  %write Host: world.altavista.com
  %write Content-Length: $len(%data)
  %write Connection: close
  %write
  %write %data
}

on *:SOCKCLOSE:babel:{
  echo -s Error: Babelfish closed the connection
  if (%babelchan) msg %babelchan Error: Babelfish closed the connection
  .timerbabel off
  unset %babel
}

on *:SOCKREAD:babel:{
  var %sread
  sockread %sread

  if (%babelcontinue) %babelt = %babelt %sread

  var %regex = /<td bgcolor=white class=s><div style=padding:10px;>(.+)$/Si
  if ($regex(babel,%sread,%regex)) {
    set %babelt $regml(babel,1)
    set %babelcontinue 1
  }

  var %regex = /(.+)<\/div><\/td>/Si
  if ($regex(babelb,%babelt,%regex)) {
    set %babelt $regml(babelb,1)
    set %babelcontinue 0
    var %babeldone 1
  }

  if (%babeldone) {
    if (%babelchan) {
      msg %babelchan %babelt
    }
    else {
      echo 3 -a " $+ %babel $+ " 
      echo -a ...translates to...
      echo 2 -a " $+ %babelt $+ "
    }
    .timerbabel off
    unset %babel*
    sockclose $sockname
  }
}


Syntax:
/babel [type] <message>
!babel [type] <message>

[type] = a valid babelfish language type (en_nl, en_fr, etc) [optional]
<message> = message to translate, max 700 chars

-genius_at_work

Last edited by genius_at_work; 01/03/07 03:37 AM.