Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Just like getLocale, why isn't there a setLocale? #1381

Closed
forhadakhan opened this issue Sep 30, 2024 · 1 comment
Closed

Just like getLocale, why isn't there a setLocale? #1381

forhadakhan opened this issue Sep 30, 2024 · 1 comment
Labels
enhancement New feature or request unconfirmed Needs triage.

Comments

@forhadakhan
Copy link

Is your feature request related to a problem? Please describe.

I tried using App Router setup without i18n routing and defined a local switcher following official example.

This solution worked fine in the local development environment but resulted in an error (Cookies can only be modified in a Server Action or Route Handler. nextjs 14.2.13) in the production environment on Vercel."

Describe the solution you'd like

I think next-intl should have a direct utility to set the locale from both client and server components. Just as we can access the current locale using getLocale in server or useLocale in client, there should be a similar feature for setting the locale.

NOTE: If I'm missing something or if such solutions already exist, please point me to the direct solution.

Describe alternatives you've considered

Alternative solutions might vary from developer to developer. I am working on a way to address this, but it would be better if there were an official solution.

@forhadakhan forhadakhan added enhancement New feature or request unconfirmed Needs triage. labels Sep 30, 2024
@amannn
Copy link
Owner

amannn commented Sep 30, 2024

The implementation of setLocale really depends on how you want to manage the locale in your app. It can be a cookie, a setting in the user profile, etc.

If it's a cookie, you can use the approach shown in example-app-router-without-i18n-routing—this example works fine on Vercel.

I'll move this to a discussion since it's a usage question.

Repository owner locked and limited conversation to collaborators Sep 30, 2024
@amannn amannn converted this issue into discussion #1382 Sep 30, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
enhancement New feature or request unconfirmed Needs triage.
Projects
None yet
Development

No branches or pull requests

2 participants