vue-i18n
vue-i18n copied to clipboard
`i18n-t` only works with `useI18n`, eventhough it's unused
Reporting a bug?
When I use the i18n-t component it does not load the translation and only uses its key as fallback unless I add some const x = useI18n() to the script setup.
Expected behavior
As I'm not using anything out of x in the component I instead expect i18n-t to work right away, without the const.
Adding the use leads to an "unused variable" (x).
Reproduction
https://stackblitz.com/edit/github-a5wazj-rqd1am?file=app.vue
System Info
- Operating System: `Linux`
- Node Version: `v16.14.2`
- Nuxt Version: `3.0.0`
- Nitro Version: `1.0.0`
- Package Manager: `[email protected]`
- Builder: `vite`
- User Config: `modules`
- Runtime Modules: `@nuxtjs/[email protected]`
- Build Modules: `-`
Additional context
Taken from https://github.com/nuxt-modules/i18n/issues/1731.
Validations
- [X] Read the Contributing Guidelines
- [X] Read the Documentation
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussions
Can confirm this issue (and the solution). Although this only happens on production builds.
@kazupon, any chances to address this issue in the upcoming release, please?
I think that this issue is difficult to solve due to vue-i18n architecture & the limitations of Vue's getCurrentInstance. I will continue to work for resolving this issue.
I'm facing the same issue when using the options API (legacy to true), is there a workaround for this?
I’m not sure what the workaround is for the options api, but for the composition api I just do useI18n() without declaring a const.
That works and prevent the ‘unused variable’ message