From da76c0076bd998302676318283e188b4feac565d Mon Sep 17 00:00:00 2001 From: userquin Date: Sat, 18 Feb 2023 01:25:03 +0100 Subject: [PATCH] fix: configure i18n locale from user preferences on load --- plugins/setup-i18n.client.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/setup-i18n.client.ts b/plugins/setup-i18n.client.ts index c9f1c9dd..1bd3e392 100644 --- a/plugins/setup-i18n.client.ts +++ b/plugins/setup-i18n.client.ts @@ -11,6 +11,12 @@ export default defineNuxtPlugin(async (nuxt) => { if (!supportLanguages.includes(lang)) userSettings.value.language = getDefaultLanguage(supportLanguages) + if (lang !== i18n.locale) { + 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], () => { if (isHydrated.value && lang !== i18n.locale) setLocale(lang)