add: i18n msgid test

This commit is contained in:
bridge
2026-01-31 13:36:14 +08:00
parent 3a4c1a5dcb
commit efa663febe
2 changed files with 43 additions and 0 deletions

View File

@@ -8,12 +8,15 @@ Usage:
"""
import gettext
import logging
from pathlib import Path
from typing import Optional
# Cache for loaded translations.
_translations: dict[str, Optional[gettext.GNUTranslations]] = {}
logger = logging.getLogger(__name__)
def _get_locale_dir() -> Path:
"""Get the locales directory path."""
@@ -99,6 +102,10 @@ def t(message: str, **kwargs) -> str:
else:
translated = message
# Check for missing translation if not in English
if _get_current_lang() != "en-US" and translated == message and message.strip():
logger.warning(f"[i18n] Missing translation for msgid: '{message}'")
if kwargs:
try:
return translated.format(**kwargs)