From efe977e7de60b6e72e39f9befeee7b391a54984f Mon Sep 17 00:00:00 2001 From: Vincent A Date: Wed, 8 May 2019 19:09:08 +0200 Subject: [PATCH] modules: adapt to translaboob changes --- modules/googletranslate/module.py | 142 +++++++++++++++--------------- modules/larousse/pages.py | 14 +-- modules/wordreference/module.py | 27 ++++-- 3 files changed, 97 insertions(+), 86 deletions(-) diff --git a/modules/googletranslate/module.py b/modules/googletranslate/module.py index c8b41a66da..2c40b5ae49 100644 --- a/modules/googletranslate/module.py +++ b/modules/googletranslate/module.py @@ -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() diff --git a/modules/larousse/pages.py b/modules/larousse/pages.py index b4f0f8e51c..dc1f268030 100644 --- a/modules/larousse/pages.py +++ b/modules/larousse/pages.py @@ -27,13 +27,13 @@ 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()} diff --git a/modules/wordreference/module.py b/modules/wordreference/module.py index ab374956fa..384e1bbc7c 100644 --- a/modules/wordreference/module.py +++ b/modules/wordreference/module.py @@ -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: -- GitLab