import type { TranslationParams } from "../../i18n"; /** Keep IDs and parameters in state so open results follow later locale changes. */ export type AdminMessage = string | { message: string; params?: Readonly>; }; export function adminMessage(message: string, params?: Exclude["params"]): AdminMessage { return { message, params }; } /** Local API diagnostics retain their code; translate only the known message body. */ export function renderAdminDiagnostic(t: (message: string) => string, diagnostic: string): string { const match = /^([a-z][a-z_]+): (.+)$/.exec(diagnostic); return match ? `${match[1]}: ${t(match[2])}` : t(diagnostic); } export function renderAdminMessage( t: (message: string, params?: TranslationParams) => string, value: AdminMessage, ): string { if (typeof value === "string") return t(value); const params = value.params && Object.fromEntries(Object.entries(value.params).map(([key, param]) => [key, typeof param === "object" ? t(param.message) : param], )); return t(value.message, params); }