aboutsummaryrefslogtreecommitdiff
path: root/client-web/source/locale.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client-web/source/locale.ts')
-rw-r--r--client-web/source/locale.ts29
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])
+}