aboutsummaryrefslogtreecommitdiff
path: root/src/stores/locale.ts
blob: ba657bf5aca71ba5c64e3010d0610dda98fdbc68 (plain) (blame)
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
29
30
31
32
33
34
35
36
37
38
39
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;