diff options
Diffstat (limited to 'test-client/locale.ts')
-rw-r--r-- | test-client/locale.ts | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/test-client/locale.ts b/test-client/locale.ts new file mode 100644 index 00000000..61d083b4 --- /dev/null +++ b/test-client/locale.ts @@ -0,0 +1,14 @@ + +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 +} |