let TR: { [key: string]: string } = {} export async function init_locale(lang: string) { const res = await fetch(`/locale/${encodeURIComponent(lang)}.json`, { headers: { "Accept": "application/json" } }) if (!res.ok) throw new Error("language pack download failed"); TR = await res.json() } export function tr(key: string, ...args: string[]): string { let s = TR[key] ?? key; if (args.length) s = s.replace(/%(s|i)/ig, () => args.shift() ?? "[not provided]") return s }