Fix incorrect source language and pronunciation (#29)

* Fix incorrect source language and pronunciation

* Add tests for source language and pronunciation
This commit is contained in:
Encrylize 2017-08-08 13:42:22 +02:00 committed by ssut
parent 04a0e6dfbb
commit 034646e289
2 changed files with 12 additions and 2 deletions

View File

@ -137,13 +137,13 @@ class Translator(object):
# actual source language that will be recognized by Google Translator when the
# src passed is equal to auto.
try:
src = data[-1][0][0]
src = data[2]
except Exception: # pragma: nocover
pass
pron = origin
try:
pron = data[0][1][-1]
pron = data[0][1][-2]
except Exception: # pragma: nocover
pass
if not PY3 and isinstance(pron, unicode) and isinstance(origin, str): # pragma: nocover

View File

@ -17,6 +17,16 @@ def test_bind_multiple_service_urls():
assert translator.detect('Hello')
def test_source_language(translator):
result = translator.translate('안녕하세요.')
assert result.src == 'ko'
def test_pronunciation(translator):
result = translator.translate('안녕하세요.', dest='ja')
assert result.pronunciation == 'Kon\'nichiwa.'
def test_latin_to_english(translator):
result = translator.translate('veritas lux mea', src='la', dest='en')
assert result.text == 'The truth is my light'