Galexrt
Galexrt
NNuxt
Created by CS on 4/21/2024 in #❓・help
Route switching when using i18n setLocale doesn't work...?
Maybe someone else can chime in that knows more about vue-i18n/ NUXT i18n module, that can help with your issue and I'll maybe get smarter about not using locale.value anymore for my case 😄
19 replies
NNuxt
Created by CS on 4/21/2024 in #❓・help
Route switching when using i18n setLocale doesn't work...?
Yeah, I can understand why. Even though the https://i18n.nuxtjs.org/docs/guide/lang-switcher#vue-i18n-caveat doesn't recommend it, I didn't get it to work another way in my app though I don't use routing prefixes in my case.
19 replies
NNuxt
Created by CS on 4/21/2024 in #❓・help
Route switching when using i18n setLocale doesn't work...?
Oh I didn't see those lines
19 replies
NNuxt
Created by CS on 4/21/2024 in #❓・help
Route switching when using i18n setLocale doesn't work...?
Yes, that code works for me to ensure the locale is set and "persisted"
const { setLocale, locale } = useI18n();
locale.value = 'en-US';
await setLocale('en-US');
const { setLocale, locale } = useI18n();
locale.value = 'en-US';
await setLocale('en-US');
19 replies
NNuxt
Created by CS on 4/21/2024 in #❓・help
Route switching when using i18n setLocale doesn't work...?
Does setting the locale var from i18n help in your case?
19 replies
NNuxt
Created by CS on 4/21/2024 in #❓・help
Route switching when using i18n setLocale doesn't work...?
I think I had a similar issue and when I used locale.value = 'en' it would work but not "persist", setLocale seems to do the persisting to cookie part if I remember correctly from the docs
19 replies
NNuxt
Created by CS on 4/21/2024 in #❓・help
Route switching when using i18n setLocale doesn't work...?
Try setting the locale.value and calling setLocale()
locale.value = userLocale.value;
await setLocale(userLocale.value);
locale.value = userLocale.value;
await setLocale(userLocale.value);
19 replies