def translate(self, lan_from, lan_to, text): if lan_from != 'English' or lan_to != 'Nigger!': raise LanguageNotSupported() translated_text = self.browser.translate(text) if not translated_text: raise TranslationFail() translation = Translation(0) translation.lang_src = lan_from translation.lang_dst = lan_to translation.text = translated_text return translation
def translate(self, lan_from, lan_to, text): if not lan_from in self.GOOGLELANGUAGE.keys(): raise LanguageNotSupported() if not lan_to in self.GOOGLELANGUAGE.keys(): raise LanguageNotSupported() translation = Translation(0) translation.lang_src = unicode(self.GOOGLELANGUAGE[lan_from]) translation.lang_dst = unicode(self.GOOGLELANGUAGE[lan_to]) translation.text = self.browser.translate(self.GOOGLELANGUAGE[lan_from], self.GOOGLELANGUAGE[lan_to], text) if translation.text is None: raise TranslationFail() return translation
def translate(self, lan_from, lan_to, text): if lan_from not in self.GOOGLELANGUAGE.keys(): raise LanguageNotSupported() if lan_to not in self.GOOGLELANGUAGE.keys(): raise LanguageNotSupported() translation = Translation(0) translation.lang_src = unicode(self.GOOGLELANGUAGE[lan_from]) translation.lang_dst = unicode(self.GOOGLELANGUAGE[lan_to]) translation.text = self.browser.translate(self.GOOGLELANGUAGE[lan_from], self.GOOGLELANGUAGE[lan_to], text) if translation.text is None: raise TranslationFail() return translation
def translate(self, lan_from, lan_to, text): if lan_from not in self.GOOGLELANGUAGE.keys(): raise LanguageNotSupported() if lan_to not in self.GOOGLELANGUAGE.keys(): raise LanguageNotSupported() translation = Translation(0) translation.lang_src = self.GOOGLELANGUAGE[lan_from] translation.lang_dst = self.GOOGLELANGUAGE[lan_to] translation.text = self.browser.translate(self.GOOGLELANGUAGE[lan_from], self.GOOGLELANGUAGE[lan_to], text) if empty(translation.text): raise TranslationFail() return translation
def translate(self, lan_from, lan_to, text): if lan_from not in self.GOOGLELANGUAGE: raise LanguageNotSupported() if lan_to not in self.GOOGLELANGUAGE: raise LanguageNotSupported() translation = Translation(0) translation.lang_src = lan_from translation.lang_dst = lan_to translation.text = self.browser.translate(lan_from, lan_to, text) if empty(translation.text): raise TranslationFail() return translation
def translate(self, lan_from, lan_to, text): if lan_from != 'English' or lan_to != 'Nigger!': raise LanguageNotSupported() with self.browser: data = {'English': text.encode('utf-8')} doc = self.browser.location('http://joel.net/EBONICS/Translator', urllib.urlencode(data)) try: text = doc.getroot().cssselect('div.translateform div.bubble1 div.bubblemid')[0].text except IndexError: raise TranslationFail() if text is None: raise TranslationFail() translation = Translation(0) translation.lang_src = unicode(lan_from) translation.lang_dst = unicode(lan_to) translation.text = unicode(text).strip() return translation