This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

GTranslate is not working because of TCL issues

Help for those learning Tcl or writing their own scripts.
r
rayvtirx
Voice
Posts: 16
Joined: Mon May 31, 2010 9:35 am
Location: bristol,england
Contact:

Post by rayvtirx »

just happened to find a different version of the same script while googling and this one works http://heartbroken.bshellz.net/gtranslate.tcl
User avatar
CrazyCat
Revered One
Posts: 1303
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Oh ! I didn't notice the version on egghelp wasn't the last one I did.

The official download is http://www.eggdrop.fr/board/downloads.p ... ew&did=209

I'll send the good version to slennox in a few hours.
r
rayvtirx
Voice
Posts: 16
Joined: Mon May 31, 2010 9:35 am
Location: bristol,england
Contact:

Post by rayvtirx »

ah cool - thanks
ill wait until its on egghelp as.. i need a translator to go on that site :P
u
ujjain
Voice
Posts: 12
Joined: Mon Oct 11, 2010 10:12 am

Post by ujjain »

I have new code, it works perfectly and is extremely light-weight and simple.

Code: Select all

administrator@artemis:~$ cat /home/administrator/eggdrop/scripts/gtranslate.tcl
namespace eval gTranslator {

# Factor this out into a helper
proc getJson url {
  set tok [http::geturl $url]
  set res [json::json2dict [http::data $tok]]
  http::cleanup $tok
  return $res
}
# How to decode _decimal_ entities; WARNING: high magic factor within!
proc decodeEntities str {
  set str [string map {\[ {\[} \] {\]} \$ {\$} \\ \\\\} $str]
  subst [regsub -all {&#(\d+);} $str {[format %c \1]}]
}

bind pub - !tr gTranslator::translate
proc translate { nick uhost handle chan text } {
  package require http
  package require json
  set lngto [string tolower [lindex [split $text] 0]]
  set text [http::formatQuery q [join [lrange [split $text] 1 end]]]
  set dturl "http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&q=$text"

  set lng [dict get [getJson $dturl] responseData language]

  if { $lng == $lngto } {
    putserv "PRIVMSG $chan :\002Error\002 translating $lng to $lngto."
    return 0
  }
  set trurl "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&langpair=$lng%7c$lngto&$text"
  putlog $trurl

  set res [getJson $trurl]

  putlog $res
  #putserv "PRIVMSG $chan :Language detected: $lng"

  set translated [decodeEntities [dict get $res responseData translatedText]]

  putserv "PRIVMSG $chan :$translated"
#  putserv "PRIVMSG $chan :[encoding convertto utf-8 $translated]"
}
}
User avatar
CrazyCat
Revered One
Posts: 1303
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

A small message to say that gTranslator doesn't work anymore and will not be released again.
Google choosed to block the API v1 and the v2 is a commercial one, I refuse to make a script which use commercial services.

@slennox: could you please remove Google Translator from the tcl archive ?

Regards,
CrazyCat
Post Reply