Commit efe977e7 authored by ntome's avatar ntome

modules: adapt to translaboob changes

parent dfc6c6cf
......@@ -38,84 +38,84 @@ class GoogleTranslateModule(Module, CapTranslate):
NAME = 'googletranslate'
DESCRIPTION = u'Google translation web service'
BROWSER = GoogleTranslateBrowser
GOOGLELANGUAGE = {
'Arabic': 'ar',
'Afrikaans': 'af',
'Albanian': 'sq',
'Armenian': 'hy',
'Azerbaijani': 'az',
'Basque': 'eu',
'Belarusian': 'be',
'Bengali': 'bn',
'Bulgarian': 'bg',
'Catalan': 'ca',
'Chinese': 'zh-CN',
'Croatian': 'hr',
'Czech': 'cs',
'Danish': 'da',
'Dutch': 'nl',
'English': 'en',
'Esperanto': 'eo',
'Estonian': 'et',
'Filipino': 'tl',
'Finnish': 'fi',
'French': 'fr',
'Galician': 'gl',
'Georgian': 'ka',
'German': 'de',
'Greek': 'el',
'Gujarati': 'gu',
'Haitian': 'ht',
'Hebrew': 'iw',
'Hindi': 'hi',
'Hungaric': 'hu',
'Icelandic': 'is',
'Indonesian': 'id',
'Irish': 'ga',
'Italian': 'it',
'Japanese': 'ja',
'Kannada': 'kn',
'Korean': 'ko',
'Latin': 'la',
'Latvian': 'lv',
'Lithuanian': 'lt',
'Macedonian': 'mk',
'Malay': 'ms',
'Maltese': 'mt',
'Norwegian': 'no',
'Persian': 'fa',
'Polish': 'pl',
'Portuguese': 'pt',
'Romanian': 'ro',
'Russian': 'ru',
'Serbian': 'sr',
'Slovak': 'sk',
'Slovenian': 'sl',
'Spanish': 'es',
'Swahili': 'sw',
'Swedish': 'sv',
'Tamil': 'ta',
'Telugu': 'te',
'Thai': 'th',
'Turkish': 'tr',
'Ukrainian': 'uk',
'Urdu': 'ur',
'Vietnamese': 'vi',
'Welsh': 'cy',
'Yiddish': 'yi',
}
GOOGLELANGUAGE = [
'ar',
'af',
'sq',
'hy',
'az',
'eu',
'be',
'bn',
'bg',
'ca',
'zh-CN',
'hr',
'cs',
'da',
'nl',
'en',
'eo',
'et',
'tl',
'fi',
'fr',
'gl',
'ka',
'de',
'el',
'gu',
'ht',
'iw',
'hi',
'hu',
'is',
'id',
'ga',
'it',
'ja',
'kn',
'ko',
'la',
'lv',
'lt',
'mk',
'ms',
'mt',
'no',
'fa',
'pl',
'pt',
'ro',
'ru',
'sr',
'sk',
'sl',
'es',
'sw',
'sv',
'ta',
'te',
'th',
'tr',
'uk',
'ur',
'vi',
'cy',
'yi',
]
def translate(self, lan_from, lan_to, text):
if lan_from not in self.GOOGLELANGUAGE.keys():
if lan_from not in self.GOOGLELANGUAGE:
raise LanguageNotSupported()
if lan_to not in self.GOOGLELANGUAGE.keys():
if lan_to not in self.GOOGLELANGUAGE:
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)
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()
......
......@@ -27,13 +27,13 @@ from weboob.browser.filters.standard import Env, CleanText
from weboob.browser.pages import HTMLPage
CODES = {
'allemand': 'German',
'anglais': 'English',
'arabe': 'Arabic',
'chinois': 'Chinese',
'espagnol': 'Spanish',
'francais': 'French',
'italien': 'Italian',
'allemand': 'de',
'anglais': 'en',
'arabe': 'ar',
'chinois': 'zh',
'espagnol': 'es',
'francais': 'fr',
'italien': 'it',
}
RCODES = {v: k for k, v in CODES.items()}
......
......@@ -36,20 +36,31 @@ class WordReferenceModule(Module, CapTranslate):
NAME = 'wordreference'
DESCRIPTION = u'Free online translator'
BROWSER = WordReferenceBrowser
WRLANGUAGE = {
'Arabic': 'ar', 'Chinese': 'zh', 'Czech': 'cz', 'English': 'en', 'French': 'fr', 'Greek': 'gr',
'Italian': 'it', 'Japanese': 'ja', 'Korean': 'ko', 'Polish': 'pl', 'Portuguese': 'pt',
'Romanian': 'ro', 'Spanish': 'es', 'Turkish': 'tr',
}
WRLANGUAGE = [
'ar',
'zh',
'cz',
'en',
'fr',
'gr',
'it',
'ja',
'ko',
'pl',
'pt',
'ro',
'es',
'tr',
]
def translate(self, lan_from, lan_to, text):
if lan_from not in self.WRLANGUAGE.keys():
if lan_from not in self.WRLANGUAGE:
raise LanguageNotSupported()
if lan_to not in self.WRLANGUAGE.keys():
if lan_to not in self.WRLANGUAGE:
raise LanguageNotSupported()
translations = self.browser.translate(self.WRLANGUAGE[lan_from], self.WRLANGUAGE[lan_to], text)
translations = self.browser.translate(lan_from, lan_to, text)
has_translation = False
for translation in translations:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment