def googleTranslate(text, languageFrom, languageTo): """ Returns a simple string translating the text from "languageFrom" to "LanguageTo" using Google Translate AJAX Service. """ LANG={ "arabic":"ar", "bulgarian":"bg", "chinese":"zh-CN", "croatian":"hr", "czech":"cs", "danish":"da", "dutch":"nl", "english":"en", "finnish":"fi", "french":"fr", "german":"de", "greek":"el", "hindi":"hi", "italian":"it", "japanese":"ja", "korean":"ko", "norwegian":"no", "polish":"pl", "portugese":"pt", "romanian":"ro", "russian":"ru", "spanish":"es", "swedish":"sv" } base_url='http://ajax.googleapis.com/ajax/services/language/translate?' langpair='%s|%s'%(LANG.get(languageFrom.lower(),languageFrom), LANG.get(languageTo.lower(),languageTo)) params=urllib.urlencode( (('v',1.0), ('q',text), ('langpair',langpair),) ) url=base_url+params d = getPage(url) d.addCallback(json.loads) d.addCallback(lambda obj: googleajax.fixGoogleText(obj['responseData']['translatedText'])) return d
def check_english(message, lang1, lang2): """minimize translation requests by diagnostically checking if message is english""" if lang2 == "en": if isEnglish(message): print "skipped translation" return message else: return googleajax.fixGoogleText(translate.fromAjax(message, lang1, lang2))
def check_english(message, lang1, lang2): """minimize translation requests by diagnostically checking if message is english""" if lang2 == "en": if isEnglish(message): print "skipped translation" return message else: return googleajax.fixGoogleText(translate.fromAjax(message, lang1, lang2)) # PING PONG while True: data = IRC.recv(1024) if VERBOSE: print data # if data.split(':')[-1] == 'End of /NAMES list.': # print "synced to channel" if data.find("PING") != -1: IRC.send("PONG" + " " + data.split()[1] + "\r\n") if data.split()[1] == "PRIVMSG": message = ":".join(data.split(":")[2:]).decode("utf-8") print type(message) print data.split(":")[2] # print datas sender = data.split(":")[1].split("!")[0] if sys.argv[1] == "-de": print "<" + sender + "> " + googleajax.fixGoogleText(translate.fromAjax(message, "en", "de")) if sys.argv[1] == "-en": print "<" + sender + "> " + googleajax.fixGoogleText(translate.fromAjax(message, "de", "en"))