import { LANGS } from "./preferences/decl.ts"; import { PREFS } from "./preferences/mod.ts"; const translations: { [key: string]: string } = {} export async function init_locale() { let lang = "en" if (PREFS.language == "system") { const nl = navigator.language.split("-")[0] if (LANGS.includes(nl)) lang = nl } if (LANGS.includes(PREFS.language)) lang = PREFS.language const resp = await fetch(`/locale/${lang}.ini`) if (!resp.ok) throw new Error("language load failed"); const ini = await resp.text() for (const line of ini.split("\n")) { if (!line.length || line == "[keks-meet]") continue const [key, value] = line.split("=", 2) translations[key] = value } console.log(translations); } export function tr(key: string, params: { [key: string]: string } = {}): string { return (translations[key] ?? `MISSING TR ${key}`).replace(/{(\w+)}/ig, (_m, n) => params[n]) }