feat(#248): bootstrap django i18n from shared locale contract
All checks were successful
CI / test-and-quality (push) Successful in 3m25s
CI / test-and-quality (pull_request) Successful in 2m58s

This commit is contained in:
2026-03-02 01:30:23 +00:00
parent 9deae85a56
commit 6838cc0efc
4 changed files with 68 additions and 21 deletions

View File

@@ -0,0 +1,30 @@
import json
from functools import lru_cache
from pathlib import Path
_LOCALE_LABELS = {
"en": "English",
"da": "Danish",
}
@lru_cache(maxsize=1)
def shared_i18n_catalog() -> dict:
catalog_path = Path(__file__).resolve().parents[1] / "shared" / "i18n" / "lobby.json"
with catalog_path.open(encoding="utf-8") as handle:
return json.load(handle)
@lru_cache(maxsize=1)
def locale_config() -> tuple[str, tuple[str, ...]]:
locales = shared_i18n_catalog().get("locales", {})
default_locale = str(locales.get("default", "en")).strip().lower() or "en"
supported_locales = tuple(
locale.strip().lower() for locale in locales.get("supported", ["en", "da"]) if str(locale).strip()
) or ("en", "da")
return default_locale, supported_locales
def django_languages() -> list[tuple[str, str]]:
_default_locale, supported_locales = locale_config()
return [(locale, _LOCALE_LABELS.get(locale, locale.upper())) for locale in supported_locales]