Skip to content

Feature Request: RoutingConfig for Locale Cookie Sync Control #1793

@AirboZH

Description

@AirboZH

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:
Image

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:

  1. Locale Cookie
  2. Browser Language Preference (used only for prompting language switching)
  3. 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:

}
}
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.

// 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions