diff options
| author | Adrien Hopkins <[email protected]> | 2022-08-23 11:43:11 -0500 |
|---|---|---|
| committer | Adrien Hopkins <[email protected]> | 2022-08-23 11:43:11 -0500 |
| commit | 5b1750b94a4bd44140cb792f676328e7ce4145cb (patch) | |
| tree | 6103df26a7e6528b652f55c9747d6f4acd5728de /src | |
| parent | a810aee9747d18666a59fb58af18aa5de6ad015d (diff) | |
| download | coinos-ui-5b1750b94a4bd44140cb792f676328e7ce4145cb.tar.gz coinos-ui-5b1750b94a4bd44140cb792f676328e7ce4145cb.zip | |
put sveltekit-i18n locale in localStorage
Diffstat (limited to 'src')
| -rw-r--r-- | src/routes/+layout.svelte | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 0485e71d..5eab20bd 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -9,7 +9,9 @@ import { goto } from '$app/navigation'; import { LoadingSplash } from '$comp'; import { warning, protectedRoutes } from '$lib/utils'; - import { t } from '$lib/translations'; + import { t, locale } from '$lib/translations'; + + const localeLocalStorageKey = 'sveltekit-i18n-locale'; $: $token = data.token; @@ -19,6 +21,13 @@ $: $selectedRate = data.user && $rate * (data.rates[data.user.currency] / data.rates.USD); onMount(() => { + let localStorageLocale = localStorage.getItem(localeLocalStorageKey); + if (localStorageLocale) locale.set(localStorageLocale); + + locale.subscribe((lng) => { + if (lng) localStorage.setItem(localeLocalStorageKey, lng); + }); + if (protectedRoutes.find((p) => $page.url.pathname.match(p))) { if (!$token) { goto('/login'); |
