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.

Cannot 'changeLanguage' with 'next-i18next'

See original GitHub issue

Describe the bug

This may be a confusion on my part on how to use ‘next-18next’, but as I understand it is a wrapper for ‘i18next’ and ‘react-i18next’, and in those I should be able to call changeLanguage. Here I can’t do that – changeLanguage is not a function, and I don’t see it anywhere. How do I access changeLanguage (and other i18Next functions) from the singleton I created like this?

const NextI18Next = require('next-i18next');

const NextI18NextInstance = new NextI18Next({
  defaultLanguage: 'es',
  otherLanguages: ['de'],
});

module.exports = NextI18NextInstance;

Occurs in next-i18next version

0.27.0

Steps to reproduce

import i18NextInstance, { withNamespaces } from ‘…/…/…/i18n’;

i18NextInstance.changeLanguage('de');

Expected behaviour

Should change the language

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

15reactions
capellinicommented, Feb 7, 2019

Hi @robert-barcelona. Please see our example index page for how to do this.

Instead of the default import, what we normally recommend is to import the named i18n import that has the changeLanguage method.

import { i18n } from '../../../i18n'

i18n.changeLanguage('de')
6reactions
isaachinmancommented, Jul 7, 2021

Ah, I get what you’re asking. No, next-i18next relies directly on the first class NextJs internationalised routing, and the NextJs router itself keeps track of the locale. You would need to make this request upstream to NextJs themselves.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot 'changeLanguage' with 'next-i18next' · Issue #168
His question was about using changeLanguage to change the language, not changing it on a route change. Also, your answer assumes we want...
Read more >
next-i18next - Is it possible to change default language ...
I'm using next-i18next to handle internationalization of my next.js app. Is it possible to change default language dynamically?
Read more >
Add a Translation Feature to Your Next.JS App Part 2 - Medium
To switch language, just use the method coming with it: changeLanguage . You can call it like this: i18n.changeLanguage(the new language) . So...
Read more >
next-i18next - npm
To change this, you can set fallbackLng . All values supported by i18next ( string , array , object and function ) are...
Read more >
Next.js Tutorial - i18nexus | Translation Management for i18next
Quickly edit, automate, and manage your translations and connect them to your website, app, or video game with the power of i18next. Localization...
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