fix: Show all sentences contained in response

This commit is contained in:
Ting-Jun Wang 2021-04-24 00:03:47 +08:00
parent c7a9b78e73
commit fb9261e8ef
Signed by: snsd0805
GPG Key ID: 8DB0D22BC1217D33
2 changed files with 12 additions and 5 deletions

View File

@ -58,5 +58,8 @@ class GoogleTranslator():
# get information block # get information block
data = eval(targetLine) data = eval(targetLine)
data = eval(data[0][2]) data = eval(data[0][2])
return data[1][0][0][5][0][0]
ans = []
for i in data[1][0][0][5]:
ans.append(i[0])
return ans

10
tui.py
View File

@ -97,11 +97,15 @@ class MainForm(npyscreen.FormBaseNew):
# When press ALT + ENTER, send request & update output's text # When press ALT + ENTER, send request & update output's text
if self.input.value != "": if self.input.value != "":
try: try:
targetText = self.translator.translate(self.input.value) targetText = self.translator.translate(self.input.value.replace('\n', ' '))
except: except:
targetText = "This is not a true translation, there exist an error." targetText = ["This is not a true translation, there exist an error."]
finally: finally:
self.output.value = targetText text = ""
for i in targetText:
text = text + i + "\n"
self.output.value = text
# refresh entire form # refresh entire form
# Though npyscreen's documentation mention that we should avoid using DISPLAY() function # Though npyscreen's documentation mention that we should avoid using DISPLAY() function