intlify / nuxt3

Nuxt 3 Module for vue-i18n-next
MIT License
202 stars 19 forks source link

`addRouterMiddleware` is not working with `@intlify/nuxt3` #51

Open aloulouamine opened 2 years ago

aloulouamine commented 2 years ago

Hello,

When using a global addRouterMiddleware from a nuxt plugin with @intlify/nuxt3the first load misses the global router middleware.

Here a reproduction example : https://stackblitz.com/edit/github-9wkf8t-t2us5t?file=plugins/middleware.ts

https://github.com/nuxt/nuxt.js/issues/13794

vis97c commented 2 years ago

You can access the global instance:

const { vueApp } = useNuxtApp();
const { t } = vueApp.__VUE_I18N__.global;
copostic commented 2 years ago

You can access the global instance:

const { vueApp } = useNuxtApp();
const { t } = vueApp.__VUE_I18N__.global;

@vis97c Any idea how to change the global locale from here ?

I tried to change the i18n.locale but it doesn't reflect on the translations ...

(Trying to do localized routes ..)

vis97c commented 2 years ago

@copostic this Is what I'm doing on my own project, basically you change locale which is a ref. I didn't have my PC at hand so I took a screenshot on my phone, sorry. Hope it helps

Screenshot_20220617-153759_Chrome

Skyost commented 2 years ago

Cleaner solution :

const { vueApp } = useNuxtApp()
vueApp.config.globalProperties.$i18n.locale = yourLocale