chore: use await changing locale on initial load

This commit is contained in:
userquin 2023-02-18 02:53:24 +01:00
parent 8fe904d0b5
commit 71923d30dd

View file

@ -11,11 +11,8 @@ export default defineNuxtPlugin(async (nuxt) => {
if (!supportLanguages.includes(lang)) if (!supportLanguages.includes(lang))
userSettings.value.language = getDefaultLanguage(supportLanguages) userSettings.value.language = getDefaultLanguage(supportLanguages)
if (lang !== i18n.locale) { if (lang !== i18n.locale)
setLocale(userSettings.value.language) await setLocale(userSettings.value.language)
// without this line, the locale not being refreshed on F5 and so the watch will change the locale twice
i18n.locale = userSettings.value.language
}
watch([$$(lang), isHydrated], () => { watch([$$(lang), isHydrated], () => {
if (isHydrated.value && lang !== i18n.locale) if (isHydrated.value && lang !== i18n.locale)