question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

i18n is undefined available under nuxt context in nuxt plugin

See original GitHub issue

Version

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:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
rchlcommented, Sep 22, 2020

context.app.i18n not context.app.$i18n. 😃

0reactions
MartinMalindacommented, Sep 22, 2020

That’s it! Thanks 🤦 It used to work before though.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found