i18n is undefined available under nuxt context in nuxt plugin
See original GitHub issueVersion
nuxt-i18n: 6.13.12 nuxt: 2.12.2
Steps to reproduce
export default (ctx: NuxtContext, inject): void => {
const { app } = ctx;
const { $axios, $i18n } = app;
// $i18n is undefined
};
What is Expected?
$i18n is undefined under ctx.app
This issue is already discussed here: https://github.com/nuxt-community/i18n-module/issues/874#issuecomment-692366233
But I didn’t want to comment on a closed issue.
I tried to implement a fix that is recommended there - registering the plugin via a module, but it didn’t fix it for me. Maybe I missed something.
modules/api-call-register.ts
import path from 'path';
export default function apiCallRegister(this: any) {
this.addPlugin(path.resolve(__dirname, '../client/plugins/apiCall.ts'));
}
plugins/apiCall.ts
export default (ctx: NuxtContext, inject): void => {
const { app } = ctx;
const { $axios, $i18n } = app;
inject('apiCall', apiCallFactory({ $axios, $i18n: $i18n as any }));
};
config:
modules: [
'nuxt-i18n',
'@nuxtjs/axios',
'@nuxtjs/sentry',
'@nuxtjs/auth',
'nuxt-user-agent',
'~~/modules/api-call-register.ts',
'~~/modules/helmet.ts',
],
plugins: [
`~/plugins/apiCall.ts`,
],
Any tips appreciated 🙏 I guess I’m missing something trivial in the module
Issue Analytics
- State:
- Created 3 years ago
- Comments:6
Top Results From Across the Web
i18n is undefined available under nuxt context in nuxt plugin
nuxt -i18n doesn't inject to context.$i18n , only to context. · There is no need to create a wrapper module really.
Read more >[Nuxt, i18n, Vuex]: How to access this.$i18n.locales from store ...
In my global state, I want to create a getter that returns a value based on this.$i18n.locale . What is the best way...
Read more >The context - Nuxt
The context provides additional objects/params from Nuxt to Vue components and is available in special nuxt lifecycle areas.
Read more >Nuxt 3 + Tailwind + Eslint + i18n + Sentry Starter - Localazy
With the right plugins and extensions, it can also scan your Vue/Nuxt files and enforce a unified coding style across your development team....
Read more >Nuxt 3 integration - Vue I18n - Intlify
If you go through this tutorial, you can learn how to integrate Vue I18n with Nuxt plugin. Requirements #. Node.js requirement for this...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
context.app.i18n
notcontext.app.$i18n
. 😃That’s it! Thanks 🤦 It used to work before though.