Code: Select all
[14:54:23] Tcl error [gTranslator::translate]: invalid command name "::http::formatQuery"
Code: Select all
package require http
namespace eval gTranslator {
set lngs { "fr" "en" "es" "de" "it" "nl" "tr" }
#---------------------------------------------------------------------#
# ***End of Settings *** #
# Do not edit below this line unless you know what you are doing! #
#---------------------------------------------------------------------#
variable author "CrazyCat"
variable versionNum "0.1"
variable versionName "gTranslator"
}
namespace eval gTranslator {
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]]
if { [lsearch $::gTranslator::lngs $lngto] == -10 } {
putserv "PRIVMSG $chan :\002Attention\002 $lngto is not valid"
return 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 res [::json::json2dict [::http::data [::http::geturl $dturl]]]
set lng [dict get $res responseData language]
if { $lng == $lngto } {
putserv "PRIVMSG $chan :\002Error:\002 Do you really think I can translate $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 [::json::json2dict [::http::data [::http::geturl $trurl]]]
putlog $res
putserv "PRIVMSG $chan :($lng) [dict get $res responseData translatedText]"
}
}
putlog "\002$::gTranslator::versionName $::gTranslator::versionNum\002 loaded"