vue-i18n icon indicating copy to clipboard operation
vue-i18n copied to clipboard

`i18n-t` only works with `useI18n`, eventhough it's unused

Open dargmuesli opened this issue 2 years ago • 5 comments
trafficstars

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

dargmuesli avatar Dec 19 '22 23:12 dargmuesli

Can confirm this issue (and the solution). Although this only happens on production builds.

jmschaap avatar Feb 20 '23 14:02 jmschaap

@kazupon, any chances to address this issue in the upcoming release, please?

DamianGlowala avatar Feb 23 '23 15:02 DamianGlowala

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.

kazupon avatar Feb 28 '23 00:02 kazupon

I'm facing the same issue when using the options API (legacy to true), is there a workaround for this?

Citriik avatar Apr 26 '23 14:04 Citriik

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

jmschaap avatar Apr 26 '23 15:04 jmschaap