import json from functools import lru_cache from pathlib import Path from django.http import JsonResponse @lru_cache(maxsize=1) def lobby_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) def lobby_i18n_errors() -> dict: return lobby_i18n_catalog().get("backend", {}).get("error_codes", {}) def api_error(*, code: str, message: str, status: int) -> JsonResponse: return JsonResponse({"error": message, "error_code": code}, status=status)