Switch locale in a nuxt plguin #1878
Unanswered
cernymatej
asked this question in
Q&A
Replies: 1 comment
-
@cernymatej you have access to vuei18n instance with: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'd like to switch the locale in my Nuxt 3 project in a plugin based on some logic in
router.beforeEach()
, however, when I try to access the i18n nuxt module in the plugin:I get a server 500 error
Must be called at the top of a 'setup' function
.What I tried:
I was able to switch the locale by using
nuxtApp.$i18n.setLocale(pageLang)
in the plugin, but that doesn't update the SEO attributes in the head (theuseLocaleHead()
ref). I assume that this is the case because it changes the locale of the Vue i18n instance but the nuxt module doesn't register the change. Please correct me if I'm wrong.How could I switch the locale in the plugin before navigating to a route & also update the nuxt i18n module refs?
I would also like the locale change to happen on the server so that the server-rendered content is not always in the default locale.
Beta Was this translation helpful? Give feedback.
All reactions