From 21764214c257949844d87e445f1a9f2736a20561 Mon Sep 17 00:00:00 2001
From: ivarlovlie <git@ivarlovlie.no>
Date: Fri, 10 Jun 2022 00:35:22 +0200
Subject: feat: Add translations to stopwatch.svelte

This commit also demonstrates how to do i18n across apps.
---
 apps/projects/src/app/index.svelte | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 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 e397de3..5c02004 100644
--- a/apps/projects/src/app/index.svelte
+++ b/apps/projects/src/app/index.svelte
@@ -2,8 +2,9 @@
 <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 "$app/lib/stores/locale";
+    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";
@@ -29,23 +30,23 @@
     console.log("Projects Startup Report", {
         prefferedLocale: navigator.language,
         timeZone: Temporal.Now.timeZone().id,
-        go_theme: get_cookie(CookieNames.theme),
-        go_locale: get_cookie(CookieNames.locale),
+        themeCookie: {name: CookieNames.theme, value: get_cookie(CookieNames.theme)},
+        localeCookie: {name: CookieNames.locale, value: get_cookie(CookieNames.locale)},
         prefersColorScheme: window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"
     });
 
     currentLocale.subscribe(async locale => {
-        locale = locale === "preffered" ? preffered_or_default() : locale;
-        await loadLocaleAsync(locale);
-        LL = i18nObject(locale);
-        setLocale(locale);
+        locale = (locale === "preffered" ? preffered_or_default() : locale);
+        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);
-        LL = i18nObject(locale);
-        setLocale(locale);
+        await loadLocaleAsync(locale as Locales);
+        LL = i18nObject(locale as Locales);
+        setLocale(locale as Locales);
         notOnlineText = LL.messages.noInternet();
     });
 
-- 
cgit v1.3

