fix(i18n): tighten prompt and catalog fallback handling

This commit is contained in:
春河晴
2026-03-13 01:59:16 +09:00
parent d418a8451b
commit 568685758b
3 changed files with 10 additions and 9 deletions

View File

@@ -7,9 +7,7 @@ from babel import Locale
from babel.dates import format_datetime as babel_format_datetime
from babel.numbers import format_decimal as babel_format_decimal
from .loaders import DEFAULT_LOCALE, extract_placeholders, format_template, to_babel_locale
__all__ = ["extract_placeholders", "format_template"]
from .loaders import DEFAULT_LOCALE, to_babel_locale
def select_plural_category(locale: str, count: int | float | Decimal) -> str:

View File

@@ -10,7 +10,8 @@ import os
import threading
from .exceptions import I18nError, InvalidLocaleError
from .formatting import format_template, select_plural_category
from .formatting import select_plural_category
from .loaders import format_template
from .loaders import DEFAULT_LOCALE, TranslationValue, get_locales_root, load_locale_catalog, normalize_locale
logger = logging.getLogger("maibot.i18n")
@@ -134,7 +135,7 @@ class I18nManager:
return format_template(template, **kwargs)
except Exception as exc:
logger.error("翻译 key '%s' 格式化失败: %s", key, exc)
return template or key
return template
def _get_translation_value(self, key: str, locale: str | None) -> tuple[TranslationValue | None, str]:
target_locale = self._resolve_locale(locale)
@@ -198,7 +199,7 @@ class I18nManager:
normalized_locale,
exc,
)
catalog = {}
return {}
with self._cache_lock:
if normalized_locale in self._catalog_cache: