From cc84f37544b0024eddac5d053b510a7e3a7d48fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Fri, 21 Jun 2024 18:03:52 +0800 Subject: [PATCH] fix --- .../LunaTranslator/LunaTranslator.py | 27 +++++++++---------- .../translator/basetranslator.py | 16 ++++++----- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/LunaTranslator/LunaTranslator/LunaTranslator.py b/LunaTranslator/LunaTranslator/LunaTranslator.py index 17c181a5..8d26fadd 100644 --- a/LunaTranslator/LunaTranslator/LunaTranslator.py +++ b/LunaTranslator/LunaTranslator/LunaTranslator.py @@ -332,20 +332,19 @@ class MAINUI: returnandembedcallback = lambda x: embedcallback(x) if embedcallback else "" - if type(res) == str: - if res.startswith(""): - if currentsignature == self.currentsignature: - self.translation_ui.displaystatus.emit( - globalconfig["fanyi"][classname]["name"] - + " " - + res[len("") :], - "red", - onlytrans, - False, - ) - if len(self.usefultranslators) == 0: - returnandembedcallback("") - return + if res.startswith(""): + if currentsignature == self.currentsignature: + self.translation_ui.displaystatus.emit( + globalconfig["fanyi"][classname]["name"] + + " " + + res[len("") :], + "red", + onlytrans, + False, + ) + if len(self.usefultranslators) == 0: + returnandembedcallback("") + return res = self.solveaftertrans(res, optimization_params) if len(res) == 0: diff --git a/LunaTranslator/LunaTranslator/translator/basetranslator.py b/LunaTranslator/LunaTranslator/translator/basetranslator.py index e0d065ee..1bfa1aef 100644 --- a/LunaTranslator/LunaTranslator/translator/basetranslator.py +++ b/LunaTranslator/LunaTranslator/translator/basetranslator.py @@ -280,16 +280,20 @@ class basetrans(commonbase): if succ: __callback("", 2) - def __callback(self, collectiterres, callback, embedcallback, _, is_iter_res): + def __callback(self, collectiterres, callback, embedcallback, ares, is_iter_res): if self.needzhconv: - _ = zhconv.convert(_, "zh-tw") - if _ == "\0": # 清除前面的输出 + ares = zhconv.convert(ares, "zh-tw") + if ares == "\0": # 清除前面的输出 collectiterres.clear() pass else: - collectiterres.append(_) - if all([_ is not None for _ in collectiterres]): - callback("".join(collectiterres), embedcallback, is_iter_res) + collectiterres.append(ares) + __ = "" + for ares in collectiterres: + if ares is None: + continue + __ += ares + callback(__, embedcallback, is_iter_res) def reinitandtrans(self, contentraw, contentsolved, is_auto_run): if self.needreinit or self.initok == False: