From fb9261e8ef37358d51ae96cb70911fce02fd99a1 Mon Sep 17 00:00:00 2001 From: Ting-Jun Wang Date: Sat, 24 Apr 2021 00:03:47 +0800 Subject: [PATCH] fix: Show all sentences contained in response --- GoogleTranslator.py | 7 +++++-- tui.py | 10 +++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/GoogleTranslator.py b/GoogleTranslator.py index b4f8822..4586271 100644 --- a/GoogleTranslator.py +++ b/GoogleTranslator.py @@ -58,5 +58,8 @@ class GoogleTranslator(): # get information block data = eval(targetLine) 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 diff --git a/tui.py b/tui.py index 3e644a1..8559ad4 100644 --- a/tui.py +++ b/tui.py @@ -97,11 +97,15 @@ class MainForm(npyscreen.FormBaseNew): # When press ALT + ENTER, send request & update output's text if self.input.value != "": try: - targetText = self.translator.translate(self.input.value) + targetText = self.translator.translate(self.input.value.replace('\n', ' ')) except: - targetText = "This is not a true translation, there exist an error." + targetText = ["This is not a true translation, there exist an error."] + finally: - self.output.value = targetText + text = "" + for i in targetText: + text = text + i + "\n" + self.output.value = text # refresh entire form # Though npyscreen's documentation mention that we should avoid using DISPLAY() function