32 lines
928 B
Python
32 lines
928 B
Python
"""i18n for CI/dev scripts.
|
|
|
|
Separate from the GRM tool's i18n (``gitea_runner_manager.i18n``) so that
|
|
CI-only translation keys don't bloat the packaged CLI.
|
|
|
|
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)
|