From 93efdbc1e7def640ec03f92a7fb447d33133c7ae Mon Sep 17 00:00:00 2001
From: ivarlovlie <git@ivarlovlie.no>
Date: Mon, 5 Dec 2022 15:02:57 +0900
Subject: feat: Show active locale in select

---
 code/app/src/lib/components/locale-switcher.svelte | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

(limited to 'code/app/src/lib/components/locale-switcher.svelte')

diff --git a/code/app/src/lib/components/locale-switcher.svelte b/code/app/src/lib/components/locale-switcher.svelte
index b0230f8..3681bf5 100644
--- a/code/app/src/lib/components/locale-switcher.svelte
+++ b/code/app/src/lib/components/locale-switcher.svelte
@@ -11,6 +11,7 @@
 
     export let _pwKey: string | undefined = undefined;
     export let tabindex: number | undefined = undefined;
+    let currentLocale = Cookies.get(CookieNames.locale);
 
     async function switch_locale(newLocale: Locales) {
         if (!newLocale || $locale === newLocale) return;
@@ -18,6 +19,7 @@
         setLocale(newLocale);
         document.querySelector("html")?.setAttribute("lang", newLocale);
         Cookies.set(CookieNames.locale, newLocale);
+        currentLocale = newLocale;
         console.log("Switched to: " + newLocale);
     }
 
@@ -49,6 +51,6 @@
     class="mt-1 mr-1 block border-none py-2 pl-3 pr-10 text-base rounded-md right-0 absolute focus:outline-none focus:ring-teal-500 sm:text-sm"
 >
     {#each locales as aLocale}
-        <option value={aLocale}>{get_locale_name(aLocale)}</option>
+        <option value={aLocale} selected={aLocale === currentLocale}>{get_locale_name(aLocale)}</option>
     {/each}
 </select>
-- 
cgit v1.3

