- 生产实证:简心/有道对长句 curl 直测均返回正确中文,但游戏内长句 不翻译且 _translate_debug 无落盘、latest.log 无任何翻译 warning → 断点在插件内链路(API 侧无问题)。 - translateChatText 入口加 INFO 诊断日志(同一原文 10 秒节流); translateWithFallback 逐源记录原始返回(ThreadLocal trace); 必应兜底结果也入 trace。 - 整条翻译链返回 null 时落盘 plugins/Sdf1_login/_translate_debug/ fail_<ts>.txt(原文 + fallback 结果 + 逐源 trace + 时间戳), 落实用户「解码失败就把原文落盘」的取证需求(扩展到整链失败)。
This commit is contained in:
@@ -144,6 +144,7 @@ public class MaterialTranslator {
|
||||
* 多源翻译,按优先级尝试,失败自动降级
|
||||
*/
|
||||
private static String translateWithFallback(String text) {
|
||||
sourceTraces.get().clear();
|
||||
for (TranslationSource source : SOURCES) {
|
||||
try {
|
||||
String result = null;
|
||||
@@ -158,10 +159,14 @@ public class MaterialTranslator {
|
||||
result = translateViaGoogle(text);
|
||||
break;
|
||||
}
|
||||
// ★ 再续11:逐源记录原始返回(落盘取证用;截断防刷盘)
|
||||
String show = result == null ? "null" : (result.length() > 120 ? result.substring(0, 120) + "…" : result);
|
||||
sourceTraces.get().add(source.name + "=" + show);
|
||||
if (result != null && !result.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
sourceTraces.get().add(source.name + "=异常:" + e.getClass().getSimpleName() + ":" + e.getMessage());
|
||||
Bukkit.getLogger().warning("[翻译] 机翻 " + source.name + " 异常: " + e.getClass().getSimpleName() + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -531,15 +536,28 @@ public class MaterialTranslator {
|
||||
if (key.isEmpty()) return null;
|
||||
String hit = chatCache.get(key);
|
||||
if (hit != null) return hit;
|
||||
// ★ 第123批再续11:全链路诊断(用户实锤:长句不翻译且无落盘)。
|
||||
// 入口 INFO 日志(同一原文 10 秒节流,防刷屏)+ 失败落盘。
|
||||
long nowMs = System.currentTimeMillis();
|
||||
Long lastLog = chatDiagLogTs.get(key);
|
||||
if (lastLog == null || nowMs - lastLog > 10000L) {
|
||||
chatDiagLogTs.put(key, nowMs);
|
||||
Bukkit.getLogger().info("[机翻诊断] 收到翻译请求 原文前40字="
|
||||
+ key.substring(0, Math.min(40, key.length())));
|
||||
}
|
||||
String zh = translateWithFallback(key);
|
||||
List<String> traces = new ArrayList<>(sourceTraces.get());
|
||||
sourceTraces.remove();
|
||||
// 现有源质量差 → 必应兜底(仅聊天整句;材料名单字不触发)
|
||||
if (isLowQualityTranslation(key, zh)) {
|
||||
String bing = translateViaBing(key);
|
||||
traces.add("必应兜底=" + (bing == null ? "null" : "[" + bing + "]"));
|
||||
if (bing != null && !bing.isEmpty() && !bing.equals(key)
|
||||
&& containsCjk(bing)) {
|
||||
zh = bing; // 必应译文更可信,以其为准
|
||||
} else {
|
||||
// 必应也没取到 → 质量差时不展示(避免英文回显污染聊天)
|
||||
dumpTranslateFail(key, zh, traces);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -548,9 +566,39 @@ public class MaterialTranslator {
|
||||
chatCache.put(key, zh);
|
||||
return zh;
|
||||
}
|
||||
dumpTranslateFail(key, zh, traces);
|
||||
return null;
|
||||
}
|
||||
|
||||
/** ★ 再续11:整条翻译链失败(返回 null)时落盘插件数据目录 _translate_debug/ */
|
||||
private static void dumpTranslateFail(String original, String zh, List<String> traces) {
|
||||
try {
|
||||
Main pl = plugin;
|
||||
if (pl == null) return;
|
||||
File dir = new File(pl.getDataFolder(), "_translate_debug");
|
||||
if (!dir.isDirectory()) dir.mkdirs();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("time=").append(System.currentTimeMillis()).append('\n');
|
||||
sb.append("type=translate_chain_fail\n");
|
||||
sb.append("original=").append(original).append('\n');
|
||||
sb.append("fallback_result=").append(zh == null ? "null" : "[" + zh + "]").append('\n');
|
||||
sb.append("--- source traces ---\n");
|
||||
if (traces.isEmpty()) sb.append("(空:translateWithFallback 未记录任何源)\n");
|
||||
for (String t : traces) sb.append(t).append('\n');
|
||||
File f = new File(dir, "fail_" + System.currentTimeMillis() + ".txt");
|
||||
try (java.io.FileWriter fw = new java.io.FileWriter(f, StandardCharsets.UTF_8)) {
|
||||
fw.write(sb.toString());
|
||||
}
|
||||
Bukkit.getLogger().warning("[翻译] 整条翻译链失败(返回 null),已落盘 " + f.getName()
|
||||
+ " 原文前40字=" + original.substring(0, Math.min(40, original.length())));
|
||||
} catch (Throwable ignored) { }
|
||||
}
|
||||
|
||||
/** ★ 再续11:聊天机翻诊断日志节流(原文 → 上次打日志时间戳) */
|
||||
private static final java.util.concurrent.ConcurrentHashMap<String, Long> chatDiagLogTs = new java.util.concurrent.ConcurrentHashMap<>();
|
||||
/** ★ 再续11:当前线程的翻译源明细(translateWithFallback 逐源追加,落盘时读出) */
|
||||
private static final ThreadLocal<List<String>> sourceTraces = ThreadLocal.withInitial(ArrayList::new);
|
||||
|
||||
/** 译文质量判定:乱码/回显/极端长度比/英文回显 → 质量差 */
|
||||
private static boolean isLowQualityTranslation(String original, String translated) {
|
||||
if (translated == null || translated.isEmpty()) return true;
|
||||
|
||||
Reference in New Issue
Block a user