Fix an issue where the result text is not returned completely (cut off)

This solves issues #10 and #12, and adds a test case for it.
This commit is contained in:
SuHun Han 2017-04-01 19:46:44 +09:00
parent d1c64a11d6
commit eaac0f1130
2 changed files with 14 additions and 1 deletions

View File

@ -123,7 +123,7 @@ class Translator(object):
data = self._translate(text, dest, src)
# this code will be updated when the format is changed.
translated = data[0][0][0]
translated = ''.join([d[0] if d[0] else '' for d in data[0]])
# actual source language that will be recognized by Google Translator when the
# src passed is equal to auto.

View File

@ -27,6 +27,19 @@ def test_unicode(translator):
assert result.text == u'こんにちは。'
def test_multiple_sentences(translator):
text = u"""Architecturally, the school has a Catholic character.
Atop the Main Building's gold dome is a golden statue of the Virgin Mary.
Immediately in front of the Main Building and facing it,
is a copper statue of Christ with arms upraised with the legend Venite Ad Me Omnes."""
result = translator.translate(text, src='en', dest='es')
assert result.text == u"""Arquitectónicamente, la escuela tiene un carácter católico.
Encima de la cúpula de oro del edificio principal es una estatua de oro de la Virgen María.
Inmediatamente frente al edificio principal y frente a él,
Es una estatua de cobre de Cristo con los brazos levantados con la leyenda Venite Ad Me Omnes."""
def test_translate_list(translator):
args = (['test', 'exam'], 'ko', 'en')
translations = translator.translate(*args)