- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 328
Description
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.
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:
- Locale Cookie
- Browser Language Preference (used only for prompting language switching)
- Default Language
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 and localePrefix: "as-needed", visiting / will set the language to the default language.
Describe the solution you'd like
I hope next-intl could offer a RoutingConfig option to disable Locale Cookie setting based on path. It would be best if next-intl exported a setLocaleCookie method. That allow me to achieve the desired behavior – implementing my own Locale Cookie logic or using setLocaleCookie 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
| } | |
| } | |
| syncCookie(request, response, locale, resolvedRouting, domain); | |
| if ( | |
| !hasRedirected && | |
| resolvedRouting.localePrefix.mode !== 'never' && | 
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
| // Prio 1: Use route prefix | |
| if (pathname) { | |
| locale = getPathnameMatch( | |
| pathname, | |
| routing.locales, | |
| routing.localePrefix | |
| )?.locale; | |
| } | 
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.
