useRouter not updating locale when changing language via i18n.changeLanguage()
See original GitHub issueBug report
Describe the bug
When changing language via a select or toggle using i18n.changeLanguage()
, the router active locale does not update to the new language.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- app with
react-i18next
setup with default options - call
i18n.changeLanguage()
on click or in a select menu and toggle between difference languages/translations
const handleLocaleChange = useCallback(
(value: Locales) => {
const localeString: Locales = value as Locales;
i18n.changeLanguage(localeString);
},
[language],
);
I am getting expected behavior for language translation, but router is not updating.
Expected behavior
i18n config for nextjs would honor the changed language and update url paths accordingly
Screenshots
System information
- OS: [ Windows]
- Browser (if applies) edge
- Version of Next.js: [10.0.0]
- Version of Node.js: [latest]
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
I18N change language in Next.JS - Stack Overflow
So I configured my I18N, everything works with default locale, but everything crashes if I want to change locale from local storage.
Read more >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 >Advanced Features: Internationalized Routing - Next.js
You can access the locale information via the Next.js router. For example, using the useRouter() hook the following properties are available: locale contains ......
Read more >How to implement i18n in Next.js - Daily.dev
A locale is a particular language supported in i18n-apps. ... With the useRouter() hook we can get the currently active locale in locale, ......
Read more >next-translate - npm
Another way of accessing the locales list to change the language is using the Next.js router . The locales list can be accessed...
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
I think it is up to those packages to leverage the new Next.js i18n capabilities. Since they were announced today it may take some time before those are updated, but probably worth a shot to open an issue there.
react-i18next
, despite the name, has nothing to do with next.js. You need to handle the logic yourself here or have a single source of truth.