コード例 #1
0
ファイル: module.py プロジェクト: yang2lalang/weboob
    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
コード例 #2
0
ファイル: module.py プロジェクト: dkremer-ledger/weboob
    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
コード例 #3
0
    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
コード例 #4
0
    def translate(self, lan_from, lan_to, text):
        if lan_from not in self.WRLANGUAGE.keys():
            raise LanguageNotSupported()

        if lan_to not in self.WRLANGUAGE.keys():
            raise LanguageNotSupported()

        translations = self.browser.translate(self.WRLANGUAGE[lan_from], self.WRLANGUAGE[lan_to], text)
        has_translation = False

        for translation in translations:
            has_translation = True
            yield translation

        if not has_translation:
            raise TranslationFail()
コード例 #5
0
ファイル: module.py プロジェクト: dkremer-ledger/weboob
    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