From 7bc0f9391a34ce190ab7c263ef0d1180f7600992 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, 9 Nov 2024 15:38:12 +0800 Subject: [PATCH] fix --- cpp/version.cmake | 2 +- py/LunaTranslator/gui/edittext.py | 11 ++------ py/LunaTranslator/gui/setting_textinput.py | 19 +++++++++++-- py/LunaTranslator/myutils/config.py | 31 +++++++++++----------- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/cpp/version.cmake b/cpp/version.cmake index c94eb2c0..e5913e67 100644 --- a/cpp/version.cmake +++ b/cpp/version.cmake @@ -1,6 +1,6 @@ set(VERSION_MAJOR 5) set(VERSION_MINOR 56) -set(VERSION_PATCH 6) +set(VERSION_PATCH 7) include(${CMAKE_CURRENT_LIST_DIR}/version/generate_product_version.cmake) \ No newline at end of file diff --git a/py/LunaTranslator/gui/edittext.py b/py/LunaTranslator/gui/edittext.py index f93496fe..c0687263 100644 --- a/py/LunaTranslator/gui/edittext.py +++ b/py/LunaTranslator/gui/edittext.py @@ -2,10 +2,10 @@ from qtsymbols import * import threading, windows import gobject, qtawesome, os, json from myutils.config import globalconfig, savehook_new_data, translatorsetting -from myutils.utils import translate_exits, dynamicapiname from myutils.wrapper import Singleton_close from gui.usefulwidget import saveposwindow, getsimplecombobox from gui.dynalang import LPushButton, LMainWindow +from gui.setting_textinput import loadvalidtss @Singleton_close @@ -153,14 +153,7 @@ class edittrans(LMainWindow): w.setLayout(qv) self.textOutput.enterpressed.connect(self.submitfunction) submit = LPushButton("确定") - vis, inter = [], [] - for fanyi in globalconfig["fanyi"]: - if fanyi == "premt": - continue - if not translate_exits(fanyi): - continue - inter.append(fanyi) - vis.append(dynamicapiname(fanyi)) + inter, vis = loadvalidtss() qv.addWidget(self.textOutput) qv.addWidget( getsimplecombobox( diff --git a/py/LunaTranslator/gui/setting_textinput.py b/py/LunaTranslator/gui/setting_textinput.py index 11e8140c..ea87a7e0 100644 --- a/py/LunaTranslator/gui/setting_textinput.py +++ b/py/LunaTranslator/gui/setting_textinput.py @@ -270,11 +270,26 @@ def loadvalidtss(): alltransvis = [] alltrans = [] for x in globalconfig["fanyi"]: + if x == "premt": + continue if not translate_exits(x): continue - alltransvis.append(dynamicapiname(x)) + tp = globalconfig["fanyi"][x].get("type", "free") + alltransvis.append( + dynamicapiname(x) + + "_(" + + { + "free": "在线翻译", + "api": "注册在线翻译", + "dev": "调试浏览器", + "pre": "预翻译", + "offline": "离线翻译", + }.get(tp, "unknown type") + + ")" + ) alltrans.append(x) - return alltrans, alltransvis + sorted_pairs = sorted(zip(alltransvis, alltrans)) + return [x[1] for x in sorted_pairs], [x[0] for x in sorted_pairs] def gethookembedgrid(self): diff --git a/py/LunaTranslator/myutils/config.py b/py/LunaTranslator/myutils/config.py index cd8ca1ac..28a8d85d 100644 --- a/py/LunaTranslator/myutils/config.py +++ b/py/LunaTranslator/myutils/config.py @@ -571,23 +571,24 @@ def loadlanguage(): languageshow = {} -def _TR(k): - if k == "": +def _TR(k: str): + if not k: return "" - try: - k.encode("ascii") + if k.isascii(): return k - except: - loadlanguage() - if "_" in k: - splits = k.split("_") - return " ".join([_TR(_) for _ in splits]) - - if k not in languageshow or languageshow[k] == "": - languageshow[k] = "" - return k - else: - return languageshow[k] + loadlanguage() + if "_" in k: + splits = k.split("_") + return " ".join([_TR(_) for _ in splits]) + __ = languageshow.get(k) + if not __: + if k.startswith("(") and k.endswith(")"): + __ = languageshow.get(k[1:-1]) + if __: + __ = "(" + __ + ")" + if not __: + __ = k + return __ lastapppath = globalconfig["lastapppath"]