"""Simple i18n for GRM console messages. Set GRM_LANG environment variable to override the default English. Supported: en, bg, de, ru, zh. """ from __future__ import annotations import json import os from pathlib import Path TRANSLATIONS: dict[str, dict[str, str]] = json.loads( (Path(__file__).parent / "translations.json").read_text(encoding="utf-8") ) def _(key: str, **kwargs: object) -> str: """Return a translated string for the given key. Translation is opt-in via the ``GRM_LANG`` environment variable. If unset, English is always returned regardless of system locale. """ lang = os.getenv("GRM_LANG", "en") if lang not in ("en", "bg", "de", "ru", "zh"): lang = "en" template = TRANSLATIONS.get(key, {}).get(lang, key) return template.format(**kwargs)