fix: 自定义翻译简体中文统一使用 zh-hans
This commit is contained in:
@@ -19,7 +19,7 @@ def translate_mymemory(text, source="zh-CN", target="es"):
|
||||
return {"ok": False, "error": str(exc)}
|
||||
|
||||
|
||||
def translate_custom(text, settings, source="zh", target="es"):
|
||||
def translate_custom(text, settings, source="zh-hans", target="es"):
|
||||
api_url = (settings.get("api_url") or "").strip()
|
||||
if not api_url:
|
||||
return {"ok": False, "error": "未配置自定义翻译接口地址"}
|
||||
@@ -30,6 +30,12 @@ def translate_custom(text, settings, source="zh", target="es"):
|
||||
except Exception:
|
||||
extra = {}
|
||||
|
||||
zh_code = extra.get("zh_code", "zh-hans")
|
||||
if source.lower() in ("zh", "zh-cn", "zh-hans"):
|
||||
source = zh_code
|
||||
if target.lower() in ("zh", "zh-cn", "zh-hans"):
|
||||
target = zh_code
|
||||
|
||||
payload = extra.get("payload", {})
|
||||
payload["q"] = text
|
||||
payload["source"] = source
|
||||
@@ -65,14 +71,18 @@ def translate_custom(text, settings, source="zh", target="es"):
|
||||
return {"ok": False, "error": str(exc)}
|
||||
|
||||
|
||||
def perform_translate(text, settings, source="zh", target="es"):
|
||||
def perform_translate(text, settings, source="zh-hans", target="es"):
|
||||
provider = (settings.get("translator") or "local").lower()
|
||||
if provider == "mymemory":
|
||||
if source.lower() in ("zh", "zh-cn", "zh-hans"):
|
||||
source = "zh-hans"
|
||||
if target.lower() in ("zh", "zh-cn", "zh-hans"):
|
||||
target = "zh-hans"
|
||||
lang_map = {
|
||||
("zh", "es"): ("zh-CN", "es"),
|
||||
("es", "zh"): ("es", "zh-CN"),
|
||||
("zh", "en"): ("zh-CN", "en"),
|
||||
("en", "zh"): ("en", "zh-CN"),
|
||||
("zh-hans", "es"): ("zh-CN", "es"),
|
||||
("es", "zh-hans"): ("es", "zh-CN"),
|
||||
("zh-hans", "en"): ("zh-CN", "en"),
|
||||
("en", "zh-hans"): ("en", "zh-CN"),
|
||||
("es", "en"): ("es", "en"),
|
||||
("en", "es"): ("en", "es"),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user