web/settings: refresh the locale state when auto mode is toggled

This commit is contained in:
wukko 2024-07-09 21:41:53 +06:00
parent 82ac838655
commit 496d440e5b
No known key found for this signature in database
GPG key ID: 3E30B3F26C7B4AA2
3 changed files with 32 additions and 4 deletions

View file

@ -0,0 +1,29 @@
<script lang="ts">
import settings from "$lib/settings";
import { device } from "$lib/device";
import { locale, locales } from "$lib/i18n/translations";
import SettingsToggle from "$components/buttons/SettingsToggle.svelte";
export let title: string;
export let description: string;
const updateLocale = () => {
if ($settings.appearance.autoLanguage) {
if ($locales.includes(device.preferredLocale)) {
$locale = device.preferredLocale;
}
} else {
$locale = $settings.appearance.language;
}
}
$: $settings.appearance.autoLanguage, updateLocale();
</script>
<SettingsToggle
settingContext="appearance"
settingId="autoLanguage"
{title}
{description}
/>

View file

@ -27,7 +27,7 @@
</h4> </h4>
<div class="right-side"> <div class="right-side">
<span class="selector-current" aria-hidden="true"> <span class="selector-current" aria-hidden="true">
{$t(`languages.${$locale}`)} {$t(`languages.${currentSetting}`)}
</span> </span>
<IconSelector /> <IconSelector />
</div> </div>

View file

@ -9,6 +9,7 @@
import SettingsToggle from "$components/buttons/SettingsToggle.svelte"; import SettingsToggle from "$components/buttons/SettingsToggle.svelte";
import LanguageDropdown from "$components/settings/LanguageDropdown.svelte"; import LanguageDropdown from "$components/settings/LanguageDropdown.svelte";
import LanguageAutoToggle from "$components/settings/LanguageAutoToggle.svelte";
</script> </script>
<SettingsCategory <SettingsCategory
@ -30,9 +31,7 @@
</SettingsCategory> </SettingsCategory>
<SettingsCategory sectionId="language" title={$t("settings.language")}> <SettingsCategory sectionId="language" title={$t("settings.language")}>
<SettingsToggle <LanguageAutoToggle
settingContext="appearance"
settingId="autoLanguage"
title={$t("settings.language.auto.title")} title={$t("settings.language.auto.title")}
description={$t("settings.language.auto.description")} description={$t("settings.language.auto.description")}
/> />