Cannot 'changeLanguage' with 'next-i18next'
See original GitHub issueDescribe 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:
- Created 5 years ago
- Comments:9 (3 by maintainers)
Top 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 >
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 Free
Top 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
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 thechangeLanguage
method.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.