Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.0.0-beta.3 - Nuxt 3 RC13] $te is not auto-imported in template - _ctx.$te is not a function #1643

Closed
2 tasks done
TheAlexLichter opened this issue Nov 13, 2022 · 5 comments

Comments

@TheAlexLichter
Copy link
Contributor

TheAlexLichter commented Nov 13, 2022

Version

@nuxtjs/i18n: 8.0.0-beta.3
nuxt:3.0.0-rc.13

Nuxt configuration

Please change to [x] if relevant for this issue:

  • Applies to a site deployed to a static server (site generated with nuxt generate)
  • Applies to a site deployed to a server with a Node backend

@nuxtjs/i18n configuration

i18n: {
    vueI18n: {
      legacy: false,
      locale: 'en',
      messages: {
        en: {
          welcome: 'Welcome',
        },
        fr: {
          welcome: 'Bienvenue',
        },
      },
    },
  },

Reproduction Link

https://stackblitz.com/edit/i18n-module-1643?file=app.vue,nuxt.config.ts,package.json

Steps to reproduce

  1. Use any config
  2. Write $te in template

What is Expected?

  • Having $te working out of the box

What is actually happening?

See _ctx.$te is not a function as error.

Copy link
Collaborator

kazupon commented Nov 14, 2022

Thank you for your reproting!

$te injected into component is no longer provided by the Composition API (setup hook or script setup) from vue-i18n v9.
https://vue-i18n.intlify.dev/api/injection.html#componentcustomproperties

The reason for the deprecation is that having that API would complicate the i18n implementation by programmatically checking for the presence of keys.

As an alternative to checking for the presence of a key, vue-i18n by default outputs a warning if the key is not present.

And also, vue-i18n provides an eslint plugin that can be used to statically check for the presence of a key.
https://eslint-plugin-vue-i18n.intlify.dev/

@kazupon kazupon closed this as completed Nov 14, 2022
@TheAlexLichter
Copy link
Contributor Author

@kazupon Thanks for the info! So there is no way to programmatically check the existence of a key and e.g. render a component based on it (except with the legacy API)?

Copy link
Collaborator

kazupon commented Nov 14, 2022

@manniL
Ah, sorry. vue-i18n have been still providing Composition API equivalent to it. 😅
You can use te:
https://vue-i18n.intlify.dev/api/composition.html#te-key-locale

const { te } = useI18n(); 

@TheAlexLichter
Copy link
Contributor Author

Good to know!

But still, $te should be automatically injected without using composition API, similar to $t, right? That's not the case (see example above).

Copy link
Collaborator

kazupon commented Nov 15, 2022

Hi!
I supported $te globaly.
Please try to install edge version @nuxtjs/[email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants