From 92f4caa7aece1a92105dab39859335ada95c1a76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <1173718158@qq.com> Date: Sat, 23 Nov 2024 21:44:07 +0800 Subject: [PATCH] . --- cpp/version.cmake | 2 +- py/LunaTranslator/LunaTranslator.py | 44 +++++++++++++------ .../translator/basetranslator.py | 11 ++--- py/LunaTranslator/translator/rengong.py | 3 +- py/files/defaultconfig/translatorsetting.json | 7 ++- py/files/lang/ar.json | 3 +- py/files/lang/cht.json | 3 +- py/files/lang/cs.json | 3 +- py/files/lang/de.json | 3 +- py/files/lang/en.json | 3 +- py/files/lang/es.json | 3 +- py/files/lang/fr.json | 3 +- py/files/lang/it.json | 3 +- py/files/lang/ja.json | 3 +- py/files/lang/ko.json | 3 +- py/files/lang/nl.json | 3 +- py/files/lang/pl.json | 3 +- py/files/lang/pt.json | 3 +- py/files/lang/ru.json | 3 +- py/files/lang/sv.json | 3 +- py/files/lang/th.json | 3 +- py/files/lang/tr.json | 3 +- py/files/lang/uk.json | 3 +- py/files/lang/vi.json | 3 +- py/files/lang/zh.json | 3 +- 25 files changed, 82 insertions(+), 45 deletions(-) diff --git a/cpp/version.cmake b/cpp/version.cmake index d75ad508..86f1a327 100644 --- a/cpp/version.cmake +++ b/cpp/version.cmake @@ -1,7 +1,7 @@ set(VERSION_MAJOR 6) set(VERSION_MINOR 5) -set(VERSION_PATCH 7) +set(VERSION_PATCH 8) set(VERSION_REVISION 0) set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}") add_library(VERSION_DEF INTERFACE) diff --git a/py/LunaTranslator/LunaTranslator.py b/py/LunaTranslator/LunaTranslator.py index 415226a0..ec2556d3 100644 --- a/py/LunaTranslator/LunaTranslator.py +++ b/py/LunaTranslator/LunaTranslator.py @@ -386,18 +386,23 @@ class MAINUI: text_solved, optimization_params = self.solvebeforetrans(text) maybehaspremt = {} + skip_other_on_success = False fix_rank = globalconfig["fix_translate_rank_rank"].copy() - - if "premt" in self.translators: + if "rengong" in self.translators: + contentraw = self.analyzecontent(text_solved, optimization_params) try: - contentraw = text_solved - for _ in optimization_params: - if isinstance(_, dict): - _gpt_dict = _.get("gpt_dict", None) - if _gpt_dict is None: - continue - contentraw = _.get("gpt_dict_origin") + res = self.translators["rengong"].translate(contentraw) + except: + print_exc() + res = None + maybehaspremt["rengong"] = res + skip_other_on_success = ( + res and self.translators["rengong"].config["skip_other_on_success"] + ) + if (not skip_other_on_success) and ("premt" in self.translators): + contentraw = self.analyzecontent(text_solved, optimization_params) + try: maybehaspremt = self.translators["premt"].translate(contentraw) except: print_exc() @@ -406,11 +411,13 @@ class MAINUI: fix_rank = fix_rank[:idx] + other + fix_rank[idx + 1 :] real_fix_rank = [] - - for engine in fix_rank: - if (engine not in self.translators) and (engine not in maybehaspremt): - continue - real_fix_rank.append(engine) + if skip_other_on_success: + real_fix_rank.append("rengong") + else: + for engine in fix_rank: + if (engine not in self.translators) and (engine not in maybehaspremt): + continue + real_fix_rank.append(engine) if len(real_fix_rank) == 0: return _showrawfunction() @@ -448,6 +455,15 @@ class MAINUI: ) return True + def analyzecontent(self, text_solved, optimization_params): + for _ in optimization_params: + if isinstance(_, dict): + _gpt_dict = _.get("gpt_dict", None) + if _gpt_dict is None: + continue + return _.get("gpt_dict_origin") + return text_solved + def _delaypreparefixrank(self, _showrawfunction, real_fix_rank): _showrawfunction() for engine in real_fix_rank: diff --git a/py/LunaTranslator/translator/basetranslator.py b/py/LunaTranslator/translator/basetranslator.py index fd2e1046..f1ff4291 100644 --- a/py/LunaTranslator/translator/basetranslator.py +++ b/py/LunaTranslator/translator/basetranslator.py @@ -188,8 +188,8 @@ class basetrans(commonbase): @property def transtype(self): # free/dev/api/offline/pre - # dev/offline/pre 无视请求间隔 - # pre不使用翻译缓存 + # dev/offline 无视请求间隔 + # pre全都有额外的处理,不走该pipeline,不使用翻译缓存 # offline不被新的请求打断 return globalconfig["fanyi"][self.typename].get("type", "free") @@ -238,8 +238,6 @@ class basetrans(commonbase): # 除了预翻译不使用翻译缓存,以及手动触发gpt翻译外,其他不管什么翻译都缓存下来。 if self.is_gpt_like and not is_auto_run: return None - if self.transtype == "pre": - return None res = self.shorttermcacheget(content) if res: return res @@ -359,8 +357,6 @@ class basetrans(commonbase): # 保存缓存 # 不管是否使用翻译缓存,都存下来 - if self.transtype == "pre": - return self.shorttermcacheset(cache_use, res) self.longtermcacheset(cache_use, res) @@ -374,6 +370,7 @@ class basetrans(commonbase): continue gpt_dict = _gpt_dict contentraw = _.get("gpt_dict_origin") + break return { "text": contentsolved, @@ -409,7 +406,7 @@ class basetrans(commonbase): self.maybeneedreinit() - if self.using_gpt_dict or self.transtype == "pre": + if self.using_gpt_dict: contentsolved = self.__parse_gpt_dict( contentsolved, optimization_params ) diff --git a/py/LunaTranslator/translator/rengong.py b/py/LunaTranslator/translator/rengong.py index e156e0a5..99a86a96 100644 --- a/py/LunaTranslator/translator/rengong.py +++ b/py/LunaTranslator/translator/rengong.py @@ -113,8 +113,7 @@ class TS(basetrans): collect.append(line) return "\n".join(collect) - def translate(self, content: dict): - content = content["contentraw"] + def translate(self, content): self.checkfilechanged( self.unsafegetcurrentgameconfig(), tuple(self.config["jsonfile"]) ) diff --git a/py/files/defaultconfig/translatorsetting.json b/py/files/defaultconfig/translatorsetting.json index 2ee8f746..366c6231 100644 --- a/py/files/defaultconfig/translatorsetting.json +++ b/py/files/defaultconfig/translatorsetting.json @@ -816,7 +816,8 @@ }, "rengong": { "args": { - "jsonfile": [] + "jsonfile": [], + "skip_other_on_success": false }, "argstype": { "jsonfile": { @@ -825,6 +826,10 @@ "dir": false, "filter": "*.json", "multi": true + }, + "skip_other_on_success": { + "type": "switch", + "name": "成功时跳过其他翻译" } } }, diff --git a/py/files/lang/ar.json b/py/files/lang/ar.json index e7c5ef2b..84bdac5c 100644 --- a/py/files/lang/ar.json +++ b/py/files/lang/ar.json @@ -792,5 +792,6 @@ "Win32字符串函数钩子": "win32 سلسلة هوك", "额外的钩子": "خطاف إضافية", "自动前进": "التلقائي إلى الأمام", - "在新窗口中查词": "البحث عن الكلمات في نافذة جديدة" + "在新窗口中查词": "البحث عن الكلمات في نافذة جديدة", + "成功时跳过其他翻译": "تخطي ترجمة أخرى عند النجاح" } \ No newline at end of file diff --git a/py/files/lang/cht.json b/py/files/lang/cht.json index da5d10df..95c63492 100644 --- a/py/files/lang/cht.json +++ b/py/files/lang/cht.json @@ -792,5 +792,6 @@ "Win32字符串函数钩子": "Win32字串函數鉤子", "额外的钩子": "額外的鉤子", "自动前进": "自動前進", - "在新窗口中查词": "在新窗口中查詞" + "在新窗口中查词": "在新窗口中查詞", + "成功时跳过其他翻译": "成功時跳過其他翻譯" } \ No newline at end of file diff --git a/py/files/lang/cs.json b/py/files/lang/cs.json index da5252b4..4b94bce8 100644 --- a/py/files/lang/cs.json +++ b/py/files/lang/cs.json @@ -792,5 +792,6 @@ "Win32字符串函数钩子": "Win32 řetězcový funkční hák", "额外的钩子": "Extra háčky", "自动前进": "Automaticky dopředu", - "在新窗口中查词": "Vyhledávání slov v novém okně" + "在新窗口中查词": "Vyhledávání slov v novém okně", + "成功时跳过其他翻译": "Přeskočit další překlady po úspěchu" } \ No newline at end of file diff --git a/py/files/lang/de.json b/py/files/lang/de.json index 122de67e..d841fb79 100644 --- a/py/files/lang/de.json +++ b/py/files/lang/de.json @@ -792,5 +792,6 @@ "Win32字符串函数钩子": "Win32 String Function Hook", "额外的钩子": "Zusätzliche Haken", "自动前进": "Automatisch vorwärts", - "在新窗口中查词": "Suche nach Wörtern in einem neuen Fenster" + "在新窗口中查词": "Suche nach Wörtern in einem neuen Fenster", + "成功时跳过其他翻译": "Andere Übersetzungen überspringen, wenn erfolgreich" } \ No newline at end of file diff --git a/py/files/lang/en.json b/py/files/lang/en.json index 7b7ad404..5130f433 100644 --- a/py/files/lang/en.json +++ b/py/files/lang/en.json @@ -792,5 +792,6 @@ "Win32字符串函数钩子": "Win32 string function hook", "额外的钩子": "Extra hooks", "自动前进": "Automatic Forward", - "在新窗口中查词": "Search for words in a new window" + "在新窗口中查词": "Search for words in a new window", + "成功时跳过其他翻译": "Skip other translations when successful" } \ No newline at end of file diff --git a/py/files/lang/es.json b/py/files/lang/es.json index 23fc017b..76f93127 100644 --- a/py/files/lang/es.json +++ b/py/files/lang/es.json @@ -792,5 +792,6 @@ "Win32字符串函数钩子": "Gancho de función de cadena Win32", "额外的钩子": "Ganchos adicionales", "自动前进": "Avance automático", - "在新窗口中查词": "Buscar palabras en una nueva ventana" + "在新窗口中查词": "Buscar palabras en una nueva ventana", + "成功时跳过其他翻译": "Saltar otras traducciones cuando tenga éxito" } \ No newline at end of file diff --git a/py/files/lang/fr.json b/py/files/lang/fr.json index 477a0386..c526d4e2 100644 --- a/py/files/lang/fr.json +++ b/py/files/lang/fr.json @@ -792,5 +792,6 @@ "Win32字符串函数钩子": "Crochet de fonction de chaîne Win32", "额外的钩子": "Crochets supplémentaires", "自动前进": "Avance automatique", - "在新窗口中查词": "Rechercher des mots dans une nouvelle fenêtre" + "在新窗口中查词": "Rechercher des mots dans une nouvelle fenêtre", + "成功时跳过其他翻译": "Sauter les autres traductions en cas de succès" } \ No newline at end of file diff --git a/py/files/lang/it.json b/py/files/lang/it.json index 7ea3ffe4..a7607020 100644 --- a/py/files/lang/it.json +++ b/py/files/lang/it.json @@ -792,5 +792,6 @@ "Win32字符串函数钩子": "Aggancio della funzione stringa Win32", "额外的钩子": "Ganci supplementari", "自动前进": "Avanti automatico", - "在新窗口中查词": "Cerca parole in una nuova finestra" + "在新窗口中查词": "Cerca parole in una nuova finestra", + "成功时跳过其他翻译": "Salta altre traduzioni quando hai successo" } \ No newline at end of file diff --git a/py/files/lang/ja.json b/py/files/lang/ja.json index a3292d33..b7f4aada 100644 --- a/py/files/lang/ja.json +++ b/py/files/lang/ja.json @@ -792,5 +792,6 @@ "Win32字符串函数钩子": "Win 32文字列関数フック", "额外的钩子": "エクストラフック", "自动前进": "自動前進", - "在新窗口中查词": "新しいウィンドウで単語を調べる" + "在新窗口中查词": "新しいウィンドウで単語を調べる", + "成功时跳过其他翻译": "成功時に他の翻訳をスキップ" } \ No newline at end of file diff --git a/py/files/lang/ko.json b/py/files/lang/ko.json index 1885301c..228519ae 100644 --- a/py/files/lang/ko.json +++ b/py/files/lang/ko.json @@ -792,5 +792,6 @@ "Win32字符串函数钩子": "Win32 문자열 함수 후크", "额外的钩子": "추가 갈고리", "自动前进": "자동 전진", - "在新窗口中查词": "새 창에서 단어 찾기" + "在新窗口中查词": "새 창에서 단어 찾기", + "成功时跳过其他翻译": "성공 시 다른 번역 건너뛰기" } \ No newline at end of file diff --git a/py/files/lang/nl.json b/py/files/lang/nl.json index 940d1af0..f88d4722 100644 --- a/py/files/lang/nl.json +++ b/py/files/lang/nl.json @@ -792,5 +792,6 @@ "Win32字符串函数钩子": "Win32 tekenfunctiehook", "额外的钩子": "Extra haken", "自动前进": "Automatisch voorwaarts", - "在新窗口中查词": "Zoeken naar woorden in een nieuw venster" + "在新窗口中查词": "Zoeken naar woorden in een nieuw venster", + "成功时跳过其他翻译": "Andere vertalingen overslaan wanneer succesvol" } \ No newline at end of file diff --git a/py/files/lang/pl.json b/py/files/lang/pl.json index 897947d1..959163a3 100644 --- a/py/files/lang/pl.json +++ b/py/files/lang/pl.json @@ -792,5 +792,6 @@ "Win32字符串函数钩子": "Hook funkcji ciągów Win32", "额外的钩子": "Dodatkowe haki", "自动前进": "Automatyczne naprzód", - "在新窗口中查词": "Wyszukiwanie słów w nowym oknie" + "在新窗口中查词": "Wyszukiwanie słów w nowym oknie", + "成功时跳过其他翻译": "Pomiń inne tłumaczenia po powodzeniu" } \ No newline at end of file diff --git a/py/files/lang/pt.json b/py/files/lang/pt.json index ca27ee02..a4e47345 100644 --- a/py/files/lang/pt.json +++ b/py/files/lang/pt.json @@ -792,5 +792,6 @@ "Win32字符串函数钩子": "Gancho de função de cadeia Win32", "额外的钩子": "Ganchos extra", "自动前进": "Avançar Automático", - "在新窗口中查词": "Procurar palavras numa nova janela" + "在新窗口中查词": "Procurar palavras numa nova janela", + "成功时跳过其他翻译": "Ignorar outras traduções quando bem sucedidas" } \ No newline at end of file diff --git a/py/files/lang/ru.json b/py/files/lang/ru.json index af60e780..134250d7 100644 --- a/py/files/lang/ru.json +++ b/py/files/lang/ru.json @@ -792,5 +792,6 @@ "Win32字符串函数钩子": "Win32 Строчный крюк", "额外的钩子": "Дополнительный крюк", "自动前进": "Автоматическое продвижение вперед", - "在新窗口中查词": "Проверка слов в новом окне" + "在新窗口中查词": "Проверка слов в новом окне", + "成功时跳过其他翻译": "Скачать другие переводы при успехе" } \ No newline at end of file diff --git a/py/files/lang/sv.json b/py/files/lang/sv.json index a2760041..4e398720 100644 --- a/py/files/lang/sv.json +++ b/py/files/lang/sv.json @@ -792,5 +792,6 @@ "Win32字符串函数钩子": "Win32 strängfunktionskrok", "额外的钩子": "Extra krokar", "自动前进": "Automatisk framåt", - "在新窗口中查词": "Sök efter ord i ett nytt fönster" + "在新窗口中查词": "Sök efter ord i ett nytt fönster", + "成功时跳过其他翻译": "Hoppa över andra översättningar när de lyckas" } \ No newline at end of file diff --git a/py/files/lang/th.json b/py/files/lang/th.json index cc1568ad..39ffde92 100644 --- a/py/files/lang/th.json +++ b/py/files/lang/th.json @@ -792,5 +792,6 @@ "Win32字符串函数钩子": "Win32 ฟังก์ชั่นสตริงตะขอ", "额外的钩子": "ตะขอเพิ่มเติม", "自动前进": "เดินหน้าอัตโนมัติ", - "在新窗口中查词": "ค้นหาคำในหน้าต่างใหม่" + "在新窗口中查词": "ค้นหาคำในหน้าต่างใหม่", + "成功时跳过其他翻译": "ข้ามการแปลอื่นเมื่อสำเร็จ" } \ No newline at end of file diff --git a/py/files/lang/tr.json b/py/files/lang/tr.json index 9327bbb8..88fdf6f1 100644 --- a/py/files/lang/tr.json +++ b/py/files/lang/tr.json @@ -792,5 +792,6 @@ "Win32字符串函数钩子": "Win32 string fonksiyonu", "额外的钩子": "Ekstra hücreler", "自动前进": "Otomatik İleri", - "在新窗口中查词": "Yeni pencerede kelimeler arayın" + "在新窗口中查词": "Yeni pencerede kelimeler arayın", + "成功时跳过其他翻译": "Başarılı olduğunda diğer çevirileri atla" } \ No newline at end of file diff --git a/py/files/lang/uk.json b/py/files/lang/uk.json index 6c8b533b..28521d57 100644 --- a/py/files/lang/uk.json +++ b/py/files/lang/uk.json @@ -792,5 +792,6 @@ "Win32字符串函数钩子": "Хук функції рядка Win32", "额外的钩子": "Додаткові хаки", "自动前进": "Автоматично вперед", - "在新窗口中查词": "Пошук слів у новому вікні" + "在新窗口中查词": "Пошук слів у новому вікні", + "成功时跳过其他翻译": "Пропустити інші переклади, якщо вони успішні" } \ No newline at end of file diff --git a/py/files/lang/vi.json b/py/files/lang/vi.json index 9f6f893b..fad27822 100644 --- a/py/files/lang/vi.json +++ b/py/files/lang/vi.json @@ -792,5 +792,6 @@ "Win32字符串函数钩子": "Win32 Chuỗi chức năng Hook", "额外的钩子": "Thêm móc", "自动前进": "Tự động chuyển tiếp", - "在新窗口中查词": "Tra từ trong cửa sổ mới" + "在新窗口中查词": "Tra từ trong cửa sổ mới", + "成功时跳过其他翻译": "Bỏ qua các bản dịch khác khi thành công" } \ No newline at end of file diff --git a/py/files/lang/zh.json b/py/files/lang/zh.json index f9cf015e..f254c066 100644 --- a/py/files/lang/zh.json +++ b/py/files/lang/zh.json @@ -792,5 +792,6 @@ "Win32字符串函数钩子": "", "额外的钩子": "", "自动前进": "", - "在新窗口中查词": "" + "在新窗口中查词": "", + "成功时跳过其他翻译": "" } \ No newline at end of file