diff options
author | metamuffin <metamuffin@disroot.org> | 2025-03-22 14:27:25 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-03-22 14:27:25 +0100 |
commit | 5d4cb7864dc3ca19669877def6c298eb96d19b16 (patch) | |
tree | 92444bfd31c9080e8c09aa7368e3f6cb4156ed35 /client-web/source/locale.ts | |
parent | 2f5d47d21dfc308c1b930cf45e13b34445d3a8e5 (diff) | |
download | keks-meet-5d4cb7864dc3ca19669877def6c298eb96d19b16.tar keks-meet-5d4cb7864dc3ca19669877def6c298eb96d19b16.tar.bz2 keks-meet-5d4cb7864dc3ca19669877def6c298eb96d19b16.tar.zst |
new translation system
Diffstat (limited to 'client-web/source/locale.ts')
-rw-r--r-- | client-web/source/locale.ts | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/client-web/source/locale.ts b/client-web/source/locale.ts new file mode 100644 index 0000000..09849cc --- /dev/null +++ b/client-web/source/locale.ts @@ -0,0 +1,29 @@ +import { PREFS } from "./preferences/mod.ts"; + +export const LANGS = ["en", "de"] + +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]) +} |