-
-
Notifications
You must be signed in to change notification settings - Fork 279
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
Feature Request: RoutingConfig for Locale Cookie Sync Control #1793
Comments
Hey, thanks for carefully writing down your thoughts!
Interesting, it's the first time I notice that a website would ignore the path in favor of a cookie value. Other websites like e.g. microsoft.com choose a different approach, where the path always wins and missing locales in the path are filled in based on a cookie value. That's the approach that Redirecting users to another language is something that needs to be done very conservatively. The Google Search Central docs on multiregional websites go as far as:
I know with the More redirects are currently not something I'm looking for. I'd argue it's also not so common for users to end up on pathnames with different locale prefixes—if you use the routing APIs from That being said, you can always compose the middleware and add custom redirects on top. I made a note of this issue in #1362 though, there are some cases where I'd wish the middleware would work a bit better. I'm not sure yet if it's a good idea to introduce more flexibility since this can also pose potential footguns, or if providing your own custom middleware is something that should be documented (that would require As a side note, the pattern of comparing the matched language on the client side with e.g. |
As a small follow-up: Navigating to another locale prefix is the mechanism that's used for updating a potential locale cookie as part of locale switchers that use I'd say the middleware and navigation APIs that are configured via If e.g. the middleware would prefer cookie values over locale prefixes, this would break an assumption of |
Thank you so much for your patient and quick response! I really appreciate it. I completely agree with the point from the Google Search Central documentation about avoiding redirects based on assumed user language. You're right to be conservative with redirects. Regarding my mention of Notion, I admire their approach specifically because it allows users to access the root path, '/', directly without any language prefix like /en or /zh. My main goal was to achieve a similar clean domain landing page. I realized that using localeDetection: false and localePrefix: "as-needed" in combination with Thank you for sharing your insights on i18n. Thinking through this and understanding your perspective has been very educational for me. You are definitely a top-tier open-source author! Keep up the great work! 🚀 |
Hey, thank you so much for your kind words—really happy to hear if this was helpful! You should definitely share the site you're working on, I'm always curious! 🙂 |
Yeah, it's this note-taking thing we're building with AI features, and we're starting out by focusing on international students. next-intl has been amazing for setting up the multi-language stuff right from the get-go. It's a key feature for us straight away! This App is still in development, but we just rolled out the official website. |
That looks like an incredibly cool and useful project! I'm a university teacher myself, so I'm naturally curious about this topic 🤓 I'll definitely follow along! |
Is your feature request related to a problem? Please describe.
I've designed a multilingual switching logic(Prefix-based routing) that prioritizes user choice over automatic redirection. Inspired by Notion's approach, this design offers a potentially mainstream solution for language preference handling on websites.
Flowchart below:

In this flow, the Locale Cookie is only modified when the user explicitly confirms, either by clicking language switch prompts or using the language selector. When a Locale Cookie exists, accessing pages with a language differing from the Locale Cookie language will result in a redirect to the language set in the Locale Cookie.
The language priority is as follows:
Currently,
next-intl
doesn't perfectly meet my needs.A key point is that
next-intl
currently prioritizes path language over the Locale Cookie.This means that even with
localeDetection: false
andlocalePrefix: "as-needed"
, visiting/
will set the language to the default language.Describe the solution you'd like
I hope
next-intl
could offer aRoutingConfig
option to disable Locale Cookie setting based on path. It would be best if next-intl exported asetLocaleCookie
method. That allow me to achieve the desired behavior – implementing my own Locale Cookie logic or usingsetLocaleCookie
method.Describe alternatives you've considered
It might be helpful to add a RoutingConfig configuration check before the syncCookie call:
next-intl/packages/next-intl/src/middleware/middleware.tsx
Lines 311 to 318 in d6c0e91
Or, perhaps include a RoutingConfig configuration check before "Prio 1: Use route prefix" to allow skipping this priority step altogether.
next-intl/packages/next-intl/src/middleware/resolveLocale.tsx
Lines 101 to 108 in d6c0e91
In fact, I've noticed a similar issue #735 in the repository. However, I believe my request might differ from that one, hence this new issue.
I'd be grateful for your feedback/suggestions, thank you.
next-intl is a very efficient tool. If it's helpful, I would be happy to submit a PR.
The text was updated successfully, but these errors were encountered: