blob: 9812972ec2ca08e4fc3b61cd11cf997ab17a999c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
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])
}
|