fix: i18n hydration on dev
This commit is contained in:
parent
f96a9417da
commit
6b90131783
2 changed files with 6 additions and 13 deletions
|
@ -1,24 +0,0 @@
|
|||
import type { VueI18n } from 'vue-i18n'
|
||||
import type { LocaleObject } from 'vue-i18n-routing'
|
||||
|
||||
export default defineNuxtPlugin(async (nuxt) => {
|
||||
const i18n = nuxt.vueApp.config.globalProperties.$i18n as VueI18n
|
||||
const { setLocale, locales } = i18n
|
||||
const supportLanguages = (locales as LocaleObject[]).map(locale => locale.code)
|
||||
const userSettings = useUserSettings()
|
||||
const lang = userSettings.value.language
|
||||
|
||||
if (process.client && !supportLanguages.includes(lang))
|
||||
userSettings.value.language = getDefaultLanguage(locales as string[])
|
||||
|
||||
if (process.server) {
|
||||
if (lang !== i18n.locale)
|
||||
await setLocale(lang)
|
||||
return
|
||||
}
|
||||
|
||||
watch(() => userSettings.value.language, (lang) => {
|
||||
if (lang !== i18n.locale)
|
||||
setLocale(lang)
|
||||
}, { immediate: true })
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue