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.

Option to change the language without using the URL

See original GitHub issue

Hi there, How we can change user language without using the url and headers detection! …

The issue with the URL is that the user when get back to the website, the language will be returned to the default language (e.g. en) not the language that the he have selected last time he visited the website (e.g fr).

So I want to store the language at localStorage on my app’s settings page … then Next.js app get the language from the localStorage.

How we can achieve that?

Thanks

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

8reactions
ChristopherHButlercommented, Sep 2, 2022

@isaachinman I’m not sure this statement is correct:

This functionality is not handled by next-i18next.

next.js has support for internationalised routing.

So next.js does by default detect the locale (language-region-script) and automatically re-route the user based on locale. You can also change the locale yourself by simply adding a button and an onClick handler something like the following:

  const onToggleLanguageClick = (newLocale) => {
    const { pathname, asPath, query } = router;
    router.push({ pathname, query }, router.asPath, { locale: newLocale });
  };

But this re-route’s the user. You cannot just change / select a language, it is tied to locale and routing. As a user of next-i18next I want to be able to select the set of translations to use independent of the user’s locale.

Tying language to locale makes an assumption about the user that they speak the language in the region they are browsing from. If I use myself as an example, I am an English speaker, but live in Norway. So I want to select language, regardless of my region.

With react-i18next I can do this with the changeLanguage function. It seems there is no equivalent offered from next-i18next. If next-i18next is responsible for deciding which set of translations to use then I believe you should be able to provide a changeLanguage function to do this.

Does this make sense / seem reasonable @isaachinman or have I misunderstood something?

3reactions
aabmetscommented, Oct 13, 2022

The solution is to use a different i18next package: medium article

Read more comments on GitHub >

github_iconTop Results From Across the Web

Option to change the language without using the URL #1746
Hi there, How we can change user language without using the url and headers detection! .. The issue with the URL is that...
Read more >
How to Change a Website That's in a Different Language to ...
Navigate to the webpage and wait for the Chrome extension to trigger a translate option. It will appear in the top right corner...
Read more >
Change Chrome languages & translate webpages - Computer
On your computer, open Chrome. · At the top right, click More More and then Settings. · At the bottom, click Advanced. ·...
Read more >
How to Change the Default Language of an Internet Browser.
On the right side of the Settings window, scroll down to the Languages section and click the Language option. Language option in Opera...
Read more >
How can I switch the language in which websites ... - Super User
I would like all websites that I visit in my Chrome browser to be displayed in English. · Open the browser settings. ·...
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