Skip to content

Commit

Permalink
Add: converter that subtitutes for special cases
Browse files Browse the repository at this point in the history
refs #2
  • Loading branch information
ssut committed Jul 17, 2015
1 parent 649ba7d commit 80a7645
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions googletrans/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 80a7645

Please # to comment.