diff options
Diffstat (limited to 'src/stores')
| -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; |