diff options
| author | Fuwn <[email protected]> | 2024-01-21 01:58:30 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-01-21 01:58:30 -0800 |
| commit | 1fb5c8c5b6008e5f9cb87e8ef01cef322d7c304f (patch) | |
| tree | 38765d3d617e2571d876e9d32fb33b0b6bf774ae /src/stores/locale.ts | |
| parent | feat(locale): finish date & time category localisation (diff) | |
| download | due.moe-1fb5c8c5b6008e5f9cb87e8ef01cef322d7c304f.tar.xz due.moe-1fb5c8c5b6008e5f9cb87e8ef01cef322d7c304f.zip | |
feat(locale): typed locale getter
Diffstat (limited to 'src/stores/locale.ts')
| -rw-r--r-- | src/stores/locale.ts | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/stores/locale.ts b/src/stores/locale.ts new file mode 100644 index 00000000..ba657bf5 --- /dev/null +++ b/src/stores/locale.ts @@ -0,0 +1,40 @@ +import { derived, type Readable } from 'svelte/store'; +import { json } from 'svelte-i18n'; +import type { Locale } from '$lib/Locale/layout'; + +// type FormatXMLElementFn<T, R = string | T | (string | T)[]> = (parts: Array<string | T>) => R; + +// interface Options { +// id?: string; +// locale?: string; +// format?: string; +// default?: string; +// values?: +// | Record< +// string, +// string | number | boolean | Date | FormatXMLElementFn<unknown> | null | undefined +// > +// | undefined; +// } + +const createLocale = () => { + return derived(json, ($json) => { + return (locale = undefined) => + new Proxy( + {}, + { + get(_target, key) { + const localisation = $json(key.toString(), locale); + + if (localisation === key.toString()) return undefined; + + return localisation; + } + } + ); + }) as Readable<(locale?: string) => Locale>; +}; + +const locale = createLocale(); + +export default locale; |