Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change language without modifying the URL (/[lang]/rest) #1159

Open
VinceBT-BG opened this issue Oct 12, 2023 · 4 comments
Open

Change language without modifying the URL (/[lang]/rest) #1159

VinceBT-BG opened this issue Oct 12, 2023 · 4 comments

Comments

@VinceBT-BG
Copy link

VinceBT-BG commented Oct 12, 2023

What version of this package are you using?
2.6.0

What problem do you want to solve?
We have a dashboard app that is hidden from search engines, so we do not need SEO, using Next 13.5 with pages router and next-translate latest version and we would like to be able to change language without adding the locale inside the url, I see that setLanguage uses next-router to pass the locale but would it be possible to allow to change the locale without changing the URL ?

What do you think is the correct solution to this problem?
Maybe there is a way to use the NEXT_LOCALE cookie or something else to accomplish the same behavior, I am not familiar enough with this library

Are you willing to submit a pull request to implement this change?
It depends of the complexity of what would have to be modified

@mbaldas
Copy link

mbaldas commented Oct 13, 2023

I'm facing a similar problem
I want a default route without being explicit on URL.. and another language to be explicit
Anyone has some idea?

@Eusebiotrigo
Copy link

Eusebiotrigo commented Dec 4, 2023

We are on the same boat, trying to switch languages without using [lang]/route. the setLanguage complains about that the next/router is not found.

Error: No router instance found.
You should only use "next/router" on the client side of your app.

Source
components/organisms/Header/index.tsx (33:14) @ locale

  31 | date.setTime(date.getTime() + expireMs);
  32 | document.cookie = `NEXT_LOCALE=${locale};expires=${date.toUTCString()};path=/`;
> 33 | setLanguage(locale);

Ok, after finding this comment #1022 (comment)
we were able to implement a language switcher using ?lang=de or ?lang=en. without /en/ or /fr/ or /en/ in the path.

@Steven-Thelin
Copy link

Attempting to implement the solution you refer to @Eusebiotrigo didn't work for me unfortunately. I still get:

Error: No router instance found.
You should only use "next/router" on the client side of your app.

😩

@J4v4Scr1pt
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants