| View previous topic :: View next topic |
| Author |
Message |
rayvtirx Voice
Joined: 31 May 2010 Posts: 16 Location: bristol,england
|
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
|
| Back to top |
|
 |
rayvtirx Voice
Joined: 31 May 2010 Posts: 16 Location: bristol,england
|
Posted: Sat Oct 08, 2011 11:52 am Post subject: |
|
|
ah cool - thanks
ill wait until its on egghelp as.. i need a translator to go on that site  |
|
| Back to top |
|
 |
ujjain Voice
Joined: 11 Oct 2010 Posts: 12
|
Posted: Sat Oct 08, 2011 6:17 pm Post subject: |
|
|
I have new code, it works perfectly and is extremely light-weight and simple.
| Code: |
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]"
}
}
|
|
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Wed Apr 04, 2012 3:12 pm Post subject: |
|
|
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 _________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
|