nuxt3 icon indicating copy to clipboard operation
nuxt3 copied to clipboard

$tm returns a list of functions

Open jbccc opened this issue 3 years ago • 1 comments

Reporting a bug?

I'm developping a website using the release candidate version of Nuxt3 (and prior to that the beta version). To this end, I of course use @intlify/nuxt3 to integrate vue-i18n within the website. Everything is working fine, thank you for the good work you put into it, except when it comes to lists in the locales json files. I have a contact form for which I need the users to enter information, and I wanted to use i18n for the translation. When calling $tm("someKeys"), I got the following function displayed : (ctx) => {const { normalize: _normalize } = ctx;return _normalize(["neededTranslation"])} I tried to call it, but it resulted in an error : TypeError: Cannot destructure property 'normalize' of 'ctx' as it is undefined.

Expected behavior

We should get the resulted key, not a function.

Reproduction A reproducible example in codesandbox is accessible here : https://codesandbox.io/s/white-worker-oxsn11

Nuxt project info



devDependencies "devDependencies": { "@intlify/nuxt3": "^0.1.10", "@nuxtjs/tailwindcss": "^5.0.0-4", "@tailwindcss/forms": "^0.5.0", "nuxt": "^3.0.0-rc.1" }, System Info

System: OS : macOS Monterey 12.3.1 (21E258) CPU : Apple M1 Memory : 8 Go Binaries: Node : v16.13.2 Yarn : v1.22.17 NPM : v8.6.0 Browsers: Safari: Version 15.4 (17613.1.17.1.13) Chrome : Version 100.0.4896.127 (official Build) (arm64)

Screenshot Capture d’écran 2022-04-26 à 13 49 10

Additional infos As shown in #55, the new 0.2.0 version of @intlify/nuxt3 does not work yet, so I still use 0.1.10.

Validations

jbccc avatar Apr 26 '22 13:04 jbccc

I think you need to use the $rt function to parse the result returned by $tm as explained here: https://vue-i18n.intlify.dev/api/composition.html#tm-key

lsalling avatar Apr 29 '22 12:04 lsalling