125 续15l-13: 移除停运的简心API(qvqa.cn)——SOURCES/enum/switch/方法/注释全清,机翻降级链改为 YOUDAO→GOOGLE→BING
Auto Release / build (push) Successful in 2m47s
Auto Release / build (push) Successful in 2m47s
This commit is contained in:
@@ -19,7 +19,7 @@ import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* 多源在线翻译工具 —— 将MC英文材料名翻译为中文。
|
||||
* 优先使用国内接口(有道/简心),失败后降级到Google。
|
||||
* 优先使用国内接口(有道),失败后降级到Google。
|
||||
* 结果缓存避免重复请求。
|
||||
*/
|
||||
public class MaterialTranslator {
|
||||
@@ -36,13 +36,12 @@ public class MaterialTranslator {
|
||||
.connectTimeout(Duration.ofSeconds(3))
|
||||
.build();
|
||||
|
||||
// 翻译源优先级(第123批再续8 用户定调):简心排第一(质量稳),
|
||||
// aa1.cn 有道排简心后面(用户给定的官方接口,准确度没问题但故障率略高),
|
||||
// Google 殿后(对非英语语种质量差,仅兜底)
|
||||
// 翻译源优先级(第123批再续8 用户定调,2026-11-20 125续15l 移除停运的简心):
|
||||
// 有道 aa1.cn 排第一(用户给定的官方接口,准确度没问题但故障率略高),
|
||||
// Google 殿后(对非英语语种质量差,仅兜底)。
|
||||
// 必应 HTML 接口服务端取不到 SPA 译文,不在 fallback 链里,
|
||||
// 只在 translateChatText 的 isLowQualityTranslation 兜底路径调用
|
||||
private static final List<TranslationSource> SOURCES = Arrays.asList(
|
||||
TranslationSource.JIANXIN,
|
||||
TranslationSource.YOUDAO,
|
||||
TranslationSource.GOOGLE
|
||||
);
|
||||
@@ -52,7 +51,6 @@ public class MaterialTranslator {
|
||||
*/
|
||||
private enum TranslationSource {
|
||||
YOUDAO("有道翻译"),
|
||||
JIANXIN("简心翻译"),
|
||||
GOOGLE("Google翻译"),
|
||||
BING("必应翻译");
|
||||
|
||||
@@ -152,9 +150,6 @@ public class MaterialTranslator {
|
||||
case YOUDAO:
|
||||
result = translateViaYoudao(text);
|
||||
break;
|
||||
case JIANXIN:
|
||||
result = translateViaJianxin(text);
|
||||
break;
|
||||
case GOOGLE:
|
||||
result = translateViaGoogle(text);
|
||||
break;
|
||||
@@ -204,34 +199,6 @@ public class MaterialTranslator {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 简心翻译API
|
||||
* URL: https://api.qvqa.cn/api/fanyi
|
||||
* 参数: text=翻译内容, source=en, target=zh
|
||||
*/
|
||||
private static String translateViaJianxin(String text) {
|
||||
try {
|
||||
String encoded = URLEncoder.encode(text, StandardCharsets.UTF_8);
|
||||
String url = "https://api.qvqa.cn/api/fanyi?text=" + encoded + "&source=en&target=zh";
|
||||
|
||||
HttpRequest req = HttpRequest.newBuilder()
|
||||
.uri(URI.create(url))
|
||||
.header("User-Agent", "Mozilla/5.0")
|
||||
.timeout(Duration.ofSeconds(3))
|
||||
.GET()
|
||||
.build();
|
||||
|
||||
HttpResponse<byte[]> resp = http.send(req, HttpResponse.BodyHandlers.ofByteArray());
|
||||
if (resp.statusCode() == 200) {
|
||||
// 返回: {"code":200,"message":"OK","data":{"sourceText":"...","targetText":"翻译结果",...}}
|
||||
return parseNestedJsonField(decodeBody(resp), "data", "targetText");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 静默降级
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Google Translate 免费接口
|
||||
*/
|
||||
@@ -367,7 +334,7 @@ public class MaterialTranslator {
|
||||
// ==================== JSON解析工具 ====================
|
||||
|
||||
/**
|
||||
* 翻译源响应体解码(第123批再续10 用户实锤:简心对长句返回 GBK 编码,
|
||||
* 翻译源响应体解码(第123批再续10:翻译源对长句可能返回 GBK 编码,
|
||||
* 插件按 UTF-8 解码得到乱码 → isLowQualityTranslation 判低质 → 必应兜底失败
|
||||
* → null → 长句不翻译。修复:先读 bytes,按 Content-Type charset 解码,
|
||||
* 无 charset 时 UTF-8 优先、GBK 回退)。
|
||||
@@ -516,7 +483,7 @@ public class MaterialTranslator {
|
||||
|
||||
/**
|
||||
* 聊天整句机翻(非简中→中)。复用 translateWithFallback 的
|
||||
* YOUDAO→JIANXIN→GOOGLE→BING 降级链(与领地系统同一套 API 流程)。
|
||||
* YOUDAO→GOOGLE→BING 降级链(与领地系统同一套 API 流程)。
|
||||
*
|
||||
* ★ 第123批再续6(用户定调「质量差的时候用必应」):现有源译文质量差时
|
||||
* (乱码/与原文相同/疑似纯英文回显),自动加译必应并以其为准——
|
||||
|
||||
Reference in New Issue
Block a user