intlify / nuxt3

Nuxt 3 Module for vue-i18n-next

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

aloulouamine opened this issue · comments

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

nuxt/nuxt#13794

You can access the global instance:

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

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 ..)

@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

Cleaner solution :

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