diff --git a/mateclaw-server/src/main/java/vip/mate/i18n/I18nService.java b/mateclaw-server/src/main/java/vip/mate/i18n/I18nService.java index b9231d06..6aa2185a 100644 --- a/mateclaw-server/src/main/java/vip/mate/i18n/I18nService.java +++ b/mateclaw-server/src/main/java/vip/mate/i18n/I18nService.java @@ -45,6 +45,28 @@ public class I18nService { } } + /** + * Resolve a message key that is expected to be optionally absent — e.g. an + * override that legitimately does not exist for every subject (a tool may + * ship its description in code rather than in the message bundle). + *
+ * Unlike {@link #msg(String, Object...)}, a missing key returns {@code null} + * and is NOT logged: the caller treats absence as "use the built-in default", + * which is normal operation rather than a misconfiguration worth a log line. + * + * @param key 消息键 + * @param args 占位符参数 + * @return 解析后的消息文本,找不到 key 时返回 {@code null} + */ + public String msgOptional(String key, Object... args) { + Locale locale = resolveLocale(); + try { + return messageSource.getMessage(key, args, locale); + } catch (Exception e) { + return null; + } + } + /** * Clear the cached Locale. Call after a language switch so that the next * {@link #msg(String, Object...)} call re-reads {@code SystemSettingService.getLanguage()}. diff --git a/mateclaw-server/src/main/java/vip/mate/tool/ToolRegistry.java b/mateclaw-server/src/main/java/vip/mate/tool/ToolRegistry.java index 8a736fe1..79c89fc8 100644 --- a/mateclaw-server/src/main/java/vip/mate/tool/ToolRegistry.java +++ b/mateclaw-server/src/main/java/vip/mate/tool/ToolRegistry.java @@ -152,9 +152,12 @@ public class ToolRegistry { for (ToolCallback cb : cbs) { String toolName = cb.getToolDefinition().name(); String descKey = "tool." + toolName + ".desc"; - String localizedDesc = i18nService.msg(descKey); - // 如果 key 被解析(不等于 key 本身),使用本地化描述 - if (!localizedDesc.equals(descKey)) { + // The i18n description is an optional override: tools without a + // bundle entry (e.g. wiki tools) keep the description declared on + // their @Tool annotation. Use msgOptional so an absent key is not + // logged as a "missing key" — that is expected, not a fault. + String localizedDesc = i18nService.msgOptional(descKey); + if (localizedDesc != null) { localizedCallbacks.add(new LocaleAwareToolCallback(cb, localizedDesc)); } else { localizedCallbacks.add(cb);