mirror of
https://gitee.com/mateos/mateclaw.git
synced 2026-09-14 19:45:08 +08:00
fix(i18n): stop logging missing-key noise for optional tool descriptions
This commit is contained in:
parent
d629c945ee
commit
b2f9976f44
@ -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).
|
||||||
|
* <p>
|
||||||
|
* 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
|
* Clear the cached Locale. Call after a language switch so that the next
|
||||||
* {@link #msg(String, Object...)} call re-reads {@code SystemSettingService.getLanguage()}.
|
* {@link #msg(String, Object...)} call re-reads {@code SystemSettingService.getLanguage()}.
|
||||||
|
|||||||
@ -152,9 +152,12 @@ public class ToolRegistry {
|
|||||||
for (ToolCallback cb : cbs) {
|
for (ToolCallback cb : cbs) {
|
||||||
String toolName = cb.getToolDefinition().name();
|
String toolName = cb.getToolDefinition().name();
|
||||||
String descKey = "tool." + toolName + ".desc";
|
String descKey = "tool." + toolName + ".desc";
|
||||||
String localizedDesc = i18nService.msg(descKey);
|
// The i18n description is an optional override: tools without a
|
||||||
// 如果 key 被解析(不等于 key 本身),使用本地化描述
|
// bundle entry (e.g. wiki tools) keep the description declared on
|
||||||
if (!localizedDesc.equals(descKey)) {
|
// 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));
|
localizedCallbacks.add(new LocaleAwareToolCallback(cb, localizedDesc));
|
||||||
} else {
|
} else {
|
||||||
localizedCallbacks.add(cb);
|
localizedCallbacks.add(cb);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user