mIRC Homepage
Posted By: DuXxXieJ Translating - 28/02/07 03:48 PM
Code:
on *:input:*: {
  if ($1 = !translate ) && ($2) {
    if ($chan = $null) {
      run http://tools.search.yahoo.com/language/translation/translate.php?doit=done&tt=text&intl=1&text= $+ $htmlfrm($2-) $+ &lp=nl_en
      halt
    }
    run http://tools.search.yahoo.com/language/translation/translate.php?doit=done&tt=text&intl=1&text= $+ $htmlfrm($2-) $+ &lp=nl_en
    halt
  }
}

on *:text:*!translate-NL-ENG*:#oceanworld,#spelops,#testt: {
  if ($chan = $null) {
    msg $chan http://tools.search.yahoo.com/language/translation/translate.php?doit=done&tt=text&intl=1&text= $+ $htmlfrm($2-) $+ &lp=nl_en
    halt
  }
  msg $chan http://tools.search.yahoo.com/language/translation/translate.php?doit=done&tt=text&intl=1&text= $+ $htmlfrm($2-) $+ &lp=nl_en
}
alias htmlfrm {
  var %i = 1,%r
  while (%i <= $len($1-)) {
    if ($mid($1-,%i,1) isalnum) { %r = %r $+ $ifmatch }
    else { %r = %r $+ % $+ $base($asc($mid($1-,%i,1)),10,16,2) }
    inc %i
  }
  return %r
}


Ok, this code is translating a text, when somebody say's !translate-NL-ENG.
It works, but it says the WEBSITE, and i wanna know the WORD, the translated word.

Somebody know's how to do that?
I've heard then i can do that.. but i don't know HOW...(Witch script)
Posted By: LonDart Re: Translating - 28/02/07 06:27 PM
All I can tell you is that that would require using Sockets, which are way beyond me.

/help sockets

Good Luck!!
Posted By: Riamus2 Re: Translating - 28/02/07 10:04 PM
Yeah, you'd need to use sockets. And I've never tried pulling data out of a form, so I'm not sure how that works. Maybe it's the same or maybe it isn't.
Posted By: genius_at_work Re: Translating - 01/03/07 03:35 AM
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
Posted By: DuXxXieJ Re: Translating - 01/03/07 04:49 PM
No sorry,
that doesn't work.
And now ALL my scripts doens't work anymore, since i've loaded and tested it. Andah : [Type] <-- ??
Posted By: DJ_Sol Re: Translating - 01/03/07 07:40 PM
Woohooo!!! Man you kick butt!! I tried to get a socket open to babelfish and couldn't figure out how to get past the whole java interface. Woohoo!!!!

/babel en_nl love is wonderful
"love is wonderful"
...translates to...
"de liefde is prachtig"

/babel en_fr love is wonderful
"love is wonderful"
...translates to...
"l'amour est merveilleux"

[11:38] sAge: omg!!!!!
[11:38] sAge: wooohooooo

Thank You SoOOOOOOO Much!!!

(I ended up making a multilingual dictionary through Wikidictionary but it needs to be cleaned up a bit. Maybe Ill post it when I do.)
Posted By: genius_at_work Re: Translating - 02/03/07 02:02 AM
Nothing about the script would stop your scripts from working (unless you already had an alias called /babel). Make sure you have the script in its own new remotes file. The person below you seems to have no problems using the script.

-genius_at_work
Posted By: DJ_Sol What I did with the translator! - 02/03/07 08:27 PM
I have been wanting this translator for a while so yesterday, as soon as I got it I set to work! The goal is to put all functions in one toolbar underneath the edit box, but I've never made a dockable toolbar before so it may take some time.

Pick ONE name from the nicklist and it will translate what they say. Set up your 2nd edit box to always show the command to translate and talk to people in the room in a different language! Or simply open the translator dialog to translate what you like!

Posted By: DuXxXieJ Re: What I did with the translator! - 02/03/07 09:20 PM
Okkies, *btw : Cool mIRC wink *Screenshot* ^^)
Posted By: DJ_Sol Re: What I did with the translator! - 02/03/07 09:49 PM
Thanks DuXxXieJ
Posted By: learn3r Re: Translating - 03/03/07 02:05 AM
this is cool may i ask what are the other types like english to spanish
Posted By: genius_at_work Re: Translating - 03/03/07 02:36 AM
zh_en Chinese-simp to English
zt_en Chinese-trad to English
en_zh English to Chinese-simp
en_zt English to Chinese-trad
en_nl English to Dutch
en_fr English to French
en_de English to German
en_el English to Greek
en_it English to Italian
en_ja English to Japanese
en_ko English to Korean
en_pt English to Portuguese
en_ru English to Russian
en_es English to Spanish
nl_en Dutch to English
nl_fr Dutch to French
fr_en French to English
fr_de French to German
fr_el French to Greek
fr_it French to Italian
fr_pt French to Portuguese
fr_nl French to Dutch
fr_es French to Spanish
de_en German to English
de_fr German to French
el_en Greek to English
el_fr Greek to French
it_en Italian to English
it_fr Italian to French
ja_en Japanese to English
ko_en Korean to English
pt_en Portuguese to English
pt_fr Portuguese to French
ru_en Russian to English
es_en Spanish to English
es_fr Spanish to French

-genius_at_work
Posted By: learn3r Re: Translating - 03/03/07 03:18 AM
cool thanks


oh i got this

i typed
!babel aaaaaa

bot responded:
aaaaaa


doesn't it should reply with wrong syntax or something?
Posted By: DJ_Sol Re: Translating - 03/03/07 03:19 AM
I got errors translating to greek. I didnt bother exploring them at all since I don't need it. I think they might have been "line too long" errors.
Posted By: genius_at_work Re: Translating - 03/03/07 04:02 AM
There is nothing wrong with that command and response. The script displays exactly what Babelfish translates. If Babelfish can't translate a word, it simply leaves it untranslated. You can enter anything you like, but if Babelfish can't translate it, nothing will change.


@DJ_Sol

Some languages are very long by nature. Short of limiting the input to fewer characters, there is nothing that can be done. Actually, you could add a :error handler that simply says "line too long" or something of that sort.

-genius_at_work
© mIRC Discussion Forums