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>
<div class="right-side">
<span class="selector-current" aria-hidden="true">
{$t(`languages.${$locale}`)}
{$t(`languages.${currentSetting}`)}
</span>
<IconSelector />
</div>

View file

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