From 88914925774d6350ead5e7cb43bad4d39290f3b6 Mon Sep 17 00:00:00 2001 From: neavo Date: Mon, 16 Dec 2024 11:06:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20-=20=E7=A9=BA=E8=AF=91?= =?UTF-8?q?=E6=96=87=E6=9D=A1=E7=9B=AE=E5=AF=BC=E8=87=B4=E8=BF=98=E5=8E=9F?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Plugin_Scripts/MToolOptimizer/MToolOptimizer.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Plugin_Scripts/MToolOptimizer/MToolOptimizer.py b/Plugin_Scripts/MToolOptimizer/MToolOptimizer.py index a3cb4c75..b14961e0 100644 --- a/Plugin_Scripts/MToolOptimizer/MToolOptimizer.py +++ b/Plugin_Scripts/MToolOptimizer/MToolOptimizer.py @@ -112,21 +112,21 @@ def on_postprocess_text(self, event: str, config: TranslatorConfig, data: list[d continue # 统计原文和译文的最大单行显示长度 - max_length_source = max(self.get_display_length(v) for v in lines_source) - max_length_translated = max(self.get_display_length(v) for v in lines_translated) + max_length_source = max(self.get_display_length(v) for v in lines_source) if len(lines_source) > 0 else 0 + max_length_translated = max(self.get_display_length(v) for v in lines_translated) if len(lines_translated) > 0 else 0 # 第一种情况:原文和译文行数相等 if len(lines_source) == len(lines_translated): data, seen = self.update_data(v, data, lines_source, lines_translated, seen) # 第二种情况:原文行数大于译文行数,且原文最大显示长度不少于译文最大显示长度 - elif (len(lines_source) > len(lines_translated) and max_length_source >= max_length_translated): + elif len(lines_source) > len(lines_translated) and max_length_source >= max_length_translated: data, seen = self.update_data(v, data, lines_source, lines_translated, seen) # 兜底的情况 else: - # 切分前,先将译文中的换行符移除,避免重复换行,切分长度为子句最大长度 - 1 + # 切分前,先将译文中的换行符移除,避免重复换行,切分长度为子句最大长度 - 2 lines_translated = self.split_string_by_display_length( - translated_text.replace("\n", "").replace("\n", ""), - max(20, max_length_source - 1) + translated_text.replace("\r", "").replace("\n", ""), + max(20, max_length_source - 2) ) data, seen = self.update_data(v, data, lines_source, lines_translated, seen)