生产实证:同一条消息 ①不带玩家ID(Hi everyone, I'm the server owner...) → 机翻正常;②带玩家ID(...named WRW who remotely...,WRW 是在线玩家) → 静默无 [机翻] 行、无 [机翻诊断] 行。curl 直测三源对占位符 @0@ 句子 均正常返回中文,API 侧无问题。断点在 tryScheduleChatTranslation 内部 某道闸(IP/URL/mod/玩家名占位符)对带玩家名长句误伤。 - 在 tryScheduleChatTranslation 每道闸前加 INFO 阶段日志: 闸1含简中/闸2含IP/闸3含URL/闸4mod词/闸5玩家名占位符(命中名单+实际 toSend)/翻译链返回(zh0 值)。同一原文 10 秒节流防刷屏。 - 再发一次带玩家名长句,日志直接显示卡在哪一闸、占位符替换后 toSend 是什么、翻译链返回什么。
This commit is contained in:
@@ -7053,6 +7053,8 @@ public class Main extends JavaPlugin
|
||||
|
||||
// ===== 英文聊天机翻(28批新增,35批去豁免) =====
|
||||
/** 机翻专用线程池(HTTP 阻塞最多 ~9s,不能占用 ForkJoinPool.commonPool) */
|
||||
/** ★ 第123批再续11:机翻调度入口诊断日志节流(原文 → 上次打日志时间戳) */
|
||||
private final java.util.concurrent.ConcurrentHashMap<String, Long> chatTransDiagTs = new java.util.concurrent.ConcurrentHashMap<>();
|
||||
private final java.util.concurrent.ExecutorService chatTransPool =
|
||||
java.util.concurrent.Executors.newFixedThreadPool(2, r -> {
|
||||
Thread t = new Thread(r, "Sdf1-chat-translator");
|
||||
@@ -7084,6 +7086,14 @@ public class Main extends JavaPlugin
|
||||
if (p == null || msg == null) return;
|
||||
String text = msg.trim();
|
||||
if (text.isEmpty()) return;
|
||||
// ★ 第123批再续11:调度入口阶段日志(同一原文 10 秒节流),定位长句静默断点
|
||||
long nowD = System.currentTimeMillis();
|
||||
Long lastD = chatTransDiagTs.get(text);
|
||||
if (lastD == null || nowD - lastD > 10000L) {
|
||||
chatTransDiagTs.put(text, nowD);
|
||||
getLogger().info("[机翻调度] 进入 玩家=" + p.getName()
|
||||
+ " 原文前30字=" + text.substring(0, Math.min(30, text.length())));
|
||||
}
|
||||
// 触发口径(第123批再续4 用户定调「非简中→自动机翻,句子不限长短」):
|
||||
// 整条消息「不含任何简体中文字符」才机翻(含简中=原样输出);
|
||||
// 不再要求 ≥3 个英文字母——德语(ä/ö/ü/ß)、日语(假名)、法语等
|
||||
@@ -7095,18 +7105,34 @@ public class Main extends JavaPlugin
|
||||
char c = text.charAt(i);
|
||||
if (c >= '一' && c <= '鿿') { hasChinese = true; break; }
|
||||
}
|
||||
if (hasChinese) return;
|
||||
if (hasChinese) {
|
||||
getLogger().info("[机翻调度] 闸1含简中→跳过 玩家=" + p.getName()
|
||||
+ " 原文前30字=" + text.substring(0, Math.min(30, text.length())));
|
||||
return;
|
||||
}
|
||||
// 触发口径(35批修订2):消息内含域名 / IPv4 / IPv6 地址的一律不发机翻 ——
|
||||
// 这类内容由过滤体系管辖(域名按 illegal_domains.txt 后缀、IP 按加白名单),
|
||||
// 对地址做机翻毫无意义(2408:8352::1 翻出来还是原样),纯浪费 API 次数。
|
||||
if (chatFilter != null) {
|
||||
if (!chatFilter.extractIpAddresses(text).isEmpty()) return;
|
||||
if (!chatFilter.extractUrls(text).isEmpty()) return;
|
||||
if (!chatFilter.extractIpAddresses(text).isEmpty()) {
|
||||
getLogger().info("[机翻调度] 闸2含IP→跳过 玩家=" + p.getName()
|
||||
+ " IP=" + chatFilter.extractIpAddresses(text));
|
||||
return;
|
||||
}
|
||||
if (!chatFilter.extractUrls(text).isEmpty()) {
|
||||
getLogger().info("[机翻调度] 闸3含URL→跳过 玩家=" + p.getName()
|
||||
+ " URL=" + chatFilter.extractUrls(text));
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 触发口径(98批):mod 客户端/模组关键词不发机翻 ——
|
||||
// "fabric" 翻成「织物」、「neoforge」翻出来还是原文,这类词翻译纯属浪费 API 次数。
|
||||
// 词表见插件数据目录 mod_keywords.txt(# 注释,每行一个词,可自增删)。
|
||||
if (MaterialTranslator.isModRelatedMessage(text)) return;
|
||||
if (MaterialTranslator.isModRelatedMessage(text)) {
|
||||
getLogger().info("[机翻调度] 闸4mod词→跳过 玩家=" + p.getName()
|
||||
+ " 原文前30字=" + text.substring(0, Math.min(30, text.length())));
|
||||
return;
|
||||
}
|
||||
// 触发口径(35批修订3/97批修复):在线玩家名内存关 —— 玩家名不是英文,不做翻译对象
|
||||
// ① 整条消息就是玩家名(名字前后无任何上下文)→ 跳过机翻,不浪费 API;
|
||||
// ② 名字夹在上下文里(如 "Notch hi there")→ 把名字摘成 @N@ 占位符、
|
||||
@@ -7146,9 +7172,14 @@ public class Main extends JavaPlugin
|
||||
final String original = text;
|
||||
final String toSend = toTranslate;
|
||||
final String sender = p.getName();
|
||||
// ★ 再续11:占位符段诊断(命中玩家名 + 实际 toSend)
|
||||
getLogger().info("[机翻调度] 闸5玩家名占位 玩家=" + p.getName()
|
||||
+ " 命中=" + usedNames + " toSend前30字=" + toSend.substring(0, Math.min(30, toSend.length())));
|
||||
java.util.concurrent.CompletableFuture.supplyAsync(
|
||||
() -> MaterialTranslator.translateChatText(toSend), chatTransPool)
|
||||
.thenAccept(zh0 -> {
|
||||
getLogger().info("[机翻调度] 翻译链返回 玩家=" + sender
|
||||
+ " zh0=" + (zh0 == null ? "null" : "[" + zh0.substring(0, Math.min(40, zh0.length())) + "]"));
|
||||
if (zh0 == null || zh0.isEmpty()) return;
|
||||
// 占位符换回玩家原名(容忍翻译API在占位符里插空格,如 "@ 1 @")
|
||||
// 有道API返回原样 "@0@";部分源可能再包一层 → 正则同时容忍 @N@ 与 @@N@@
|
||||
|
||||
Reference in New Issue
Block a user