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.

useRouter not updating locale when changing language via i18n.changeLanguage()

See original GitHub issue

Bug 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:

  1. app with react-i18next setup with default options
  2. 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:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
balazsorban44commented, Oct 27, 2020

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.

2reactions
santialbocommented, Oct 27, 2020

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.

Read more comments on GitHub >

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

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