Skip to content

Commit 396cb0f

Browse files
author
Your Name
committed
feat: enhance locale handling in settings for improved validation and binding
1 parent 2535b75 commit 396cb0f

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

app/pages/settings.vue

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script setup lang="ts">
2+
import type { LocaleObject } from '@nuxtjs/i18n'
3+
24
const router = useRouter()
35
const { settings } = useSettings()
46
const { locale, locales, setLocale: setNuxti18nLocale } = useI18n()
@@ -8,13 +10,21 @@ const keyboardShortcutsEnabled = useKeyboardShortcuts()
810
const { toggleCodeLigatures } = useCodeLigatures()
911
1012
// Create a computed property to handle locale binding properly
13+
const localeCodes = computed<LocaleObject['code'][]>(() =>
14+
locales.value.map(loc => loc.code as LocaleObject['code']),
15+
)
16+
17+
function isLocaleCode(value: string): value is LocaleObject['code'] {
18+
return localeCodes.value.includes(value as LocaleObject['code'])
19+
}
20+
1121
const currentLocale = computed<string>({
1222
get: () => locale.value as string,
1323
set: (newLocale: string) => {
14-
if (newLocale) {
15-
settings.value.selectedLocale = newLocale as any
16-
setNuxti18nLocale(newLocale as any)
17-
}
24+
if (!newLocale || !isLocaleCode(newLocale)) return
25+
26+
settings.value.selectedLocale = newLocale
27+
setNuxti18nLocale(newLocale)
1828
},
1929
})
2030
@@ -41,11 +51,7 @@ useSeoMeta({
4151
twitterDescription: () => $t('settings.meta_description'),
4252
})
4353
44-
defineOgImageComponent('Default', {
45-
title: () => $t('settings.title'),
46-
description: () => $t('settings.tagline'),
47-
primaryColor: '#60a5fa',
48-
})
54+
4955
</script>
5056

5157
<template>

0 commit comments

Comments
 (0)