Files
grm/src/gitea_runner_manager/i18n.py
T
emil 0c6c735000
Post-merge Vikunja update / vikunja (push) Successful in 7s
CI / quality (push) Successful in 1m5s
CI / molecule-tests (1) (push) Successful in 6m26s
CI / molecule-tests (0) (push) Successful in 8m50s
CI / molecule-tests (2) (push) Successful in 5m55s
GRM-30: feat: add runner labels support and refactor i18n to JSON
2026-06-20 18:42:39 +00:00

29 lines
811 B
Python

"""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)