From ba9f3b475dcde1cbf8bff87f9eec9654c17e70a4 Mon Sep 17 00:00:00 2001
From: ivarlovlie <git@ivarlovlie.no>
Date: Sun, 12 Jun 2022 14:28:11 +0200
Subject: feat: Simplify locale determination

---
 apps/projects/src/app/index.svelte | 35 +++++++++++++++++------------------
 1 file changed, 17 insertions(+), 18 deletions(-)

(limited to 'apps/projects/src/app/index.svelte')

diff --git a/apps/projects/src/app/index.svelte b/apps/projects/src/app/index.svelte
index 5c02004..c121a32 100644
--- a/apps/projects/src/app/index.svelte
+++ b/apps/projects/src/app/index.svelte
@@ -2,26 +2,26 @@
 <svelte:window bind:online={online}/>
 
 <script lang="ts">
-    import {Locales} from "$app/lib/i18n/i18n-types";
-    import {logout_user} from "$app/lib/services/user-service";
-    import {currentLocale, preffered_or_default} from "$shared/lib/locale";
-    import {CookieNames} from "$shared/lib/configuration";
-    import {get_cookie} from "$shared/lib/helpers";
-    import {Temporal} from "@js-temporal/polyfill";
-    import {onMount} from "svelte";
+    import { Locales } from "$app/lib/i18n/i18n-types";
+    import { logout_user } from "$app/lib/services/user-service";
+    import { currentLocale, preffered_or_default } from "$shared/lib/locale";
+    import { CookieNames } from "$shared/lib/configuration";
+    import { get_cookie } from "$shared/lib/helpers";
+    import { Temporal } from "@js-temporal/polyfill";
+    import { onMount } from "svelte";
     import Router from "svelte-spa-router";
-    import {wrap} from "svelte-spa-router/wrap";
-    import {QueryClient, QueryClientProvider} from "@sveltestack/svelte-query";
-    import {is_active} from "$shared/lib/session";
+    import { wrap } from "svelte-spa-router/wrap";
+    import { QueryClient, QueryClientProvider } from "@sveltestack/svelte-query";
+    import { is_active } from "$shared/lib/session";
     import UiWorkbench from "$app/pages/ui-workbench.svelte";
     import NotFound from "$app/pages/not-found.svelte";
     import Home from "$app/pages/home.svelte";
     import Settings from "$app/pages/settings.svelte";
     import Data from "$app/pages/data.svelte";
     import PreHeader from "$shared/components/pre-header.svelte";
-    import {setLocale} from "$app/lib/i18n/i18n-svelte";
-    import {loadLocaleAsync} from "$app/lib/i18n/i18n-util.async";
-    import {i18nObject} from "$app/lib/i18n/i18n-util";
+    import { setLocale } from "$app/lib/i18n/i18n-svelte";
+    import { loadLocaleAsync } from "$app/lib/i18n/i18n-util.async";
+    import { i18nObject } from "$app/lib/i18n/i18n-util";
 
     let online = true;
     let notOnlineText;
@@ -36,17 +36,16 @@
     });
 
     currentLocale.subscribe(async locale => {
-        locale = (locale === "preffered" ? preffered_or_default() : locale);
+        if (locale === "preffered") locale = preffered_or_default();
         await loadLocaleAsync(locale as Locales);
         LL = i18nObject(locale as Locales);
         setLocale(locale as Locales);
     });
 
     onMount(async () => {
-        const locale = $currentLocale === "preffered" ? preffered_or_default() : $currentLocale;
-        await loadLocaleAsync(locale as Locales);
-        LL = i18nObject(locale as Locales);
-        setLocale(locale as Locales);
+        await loadLocaleAsync($currentLocale);
+        LL = i18nObject($currentLocale);
+        setLocale($currentLocale);
         notOnlineText = LL.messages.noInternet();
     });
 
-- 
cgit v1.3

