Fix lang switcher

This commit is contained in:
2024-07-14 16:40:49 +02:00
parent b751a5e7b3
commit 0b1e57a6dd

View File

@@ -87,6 +87,7 @@ async function changeLocale(newLocale?: string) {
const currentLocaleIndex = availableLocales.findIndex(l => l === locale.value) const currentLocaleIndex = availableLocales.findIndex(l => l === locale.value)
const nextLocaleIndex = (currentLocaleIndex + 1) % availableLocales.length const nextLocaleIndex = (currentLocaleIndex + 1) % availableLocales.length
newLocale = availableLocales[nextLocaleIndex] newLocale = availableLocales[nextLocaleIndex]
lang.value = newLocale
} }
await setLocale(newLocale ?? 'en') await setLocale(newLocale ?? 'en')
@@ -96,9 +97,9 @@ async function changeLocale(newLocale?: string) {
document.body.style.animation = '' document.body.style.animation = ''
} }
const currentLocale = computed(() => locales.value.filter(l => l.code === locale.value)[0])
const lang = ref(locale.value) const lang = ref(locale.value)
watch(lang, () => changeLocale(lang.value)) watch(lang, () => changeLocale(lang.value))
const currentLocale = computed(() => locales.value.filter(l => l.code === locale.value)[0])
const router = useRouter() const router = useRouter()
defineShortcuts({ defineShortcuts({
@@ -140,6 +141,7 @@ defineShortcuts({
variant="solid" variant="solid"
/> />
</UTooltip> </UTooltip>
{{ lang }}
<ClientOnly> <ClientOnly>
<UTooltip <UTooltip
:shortcuts="['T']" :shortcuts="['T']"
@@ -173,6 +175,13 @@ defineShortcuts({
class="w-5 h-5" class="w-5 h-5"
/> />
</template> </template>
<template #option="{ option: language }">
<UIcon
:name="language.icon"
class="w-5 h-5"
/>
<span>{{ language.code }}</span>
</template>
</USelectMenu> </USelectMenu>
</UTooltip> </UTooltip>
</ClientOnly> </ClientOnly>