From 80a76450d2f1e8a59b93429a2c4f4059acd7598a Mon Sep 17 00:00:00 2001 From: ssut Date: Sat, 18 Jul 2015 00:20:25 +0900 Subject: [PATCH] Add: converter that subtitutes for special cases refs #2 --- googletrans/translator.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/googletrans/translator.py b/googletrans/translator.py index 90dda24..9a0a941 100644 --- a/googletrans/translator.py +++ b/googletrans/translator.py @@ -12,7 +12,7 @@ from . import __version__ from googletrans import urls from googletrans.conversion import format_json -from googletrans.conversion import LANGUAGES +from googletrans.conversion import LANGUAGES, SPECIAL_CASES from googletrans.response import Translated, Detected user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36 Gt/{0}'.format(__version__) @@ -74,11 +74,16 @@ def translate(text, dest='en', src='auto'): result.append(translated) return result - if dest not in LANGUAGES.keys(): - raise ValueError('incorrect destination language') - if src != 'auto' and src not in LANGUAGES.keys(): + if src != 'auto' and src not in LANGUAGES.keys() and src in SPECIAL_CASES.keys(): + src = SPECIAL_CASES[src] + elif src != 'auto' and src not in LANGUAGES.keys(): raise ValueError('incorrect source language') + if dest not in LANGUAGES.keys() and dest in SPECIAL_CASES.keys(): + dest = SPECIAL_CASES[dest] + elif dest not in LANGUAGES.keys(): + raise ValueError('incorrect destination language') + result = '' sess = agent() # acquire requests session origin = text