NuxtI18n - Access global i18n outside of components or even composables
I am trying to implement NuxtI18n after using VueI18n. In some composables, I can use
useI18n()
or useNuxtApp().$i18n
. How can I achieve the same behavior as the code below in nuxtI18n?
I've tried things like this, but sometimes calling these composables throws errors
If I ran either in a composable, they usually work, but not always. Like when I run the composable in a worker
3 Replies
It really seems like my best bet is to skip nuxti18n entirely and create a manual plugin with vuei18n
As long as youre using the composable inside of setup this should work
const { t } = useI18n()
For outside the context try const t = useNuxtApp().$i18n.t
(do not destructure)This still causes the same error when calling
useNuxtApp
without destructuring. Is it because it is being run on a worker thread?
Perhaps I could pass context to the worker