amannn / next-intl

🌐 Internationalization (i18n) for Next.js
https://next-intl-docs.vercel.app
MIT License
2.58k stars 236 forks source link

feat: Add `localeCookie` option for middleware #1414

Closed amannn closed 1 month ago

amannn commented 1 month ago

Users have in various issues expressed the interest for customization of the locale cookie that the middleware sets. This PR adds such a capability via a new localeCookie option that can be configured via defineRouting:

import {defineRouting} from 'next-intl/routing';

export const routing = defineRouting({
  // ...
  localeCookie: {
    // Expire in 5 hours
    maxAge: 60 * 60 * 5
  }
});

… or turn the cookie off entirely:

import {defineRouting} from 'next-intl/routing';

export const routing = defineRouting({
  // ...
  localeCookie: false
});

See also: Proposed docs


Fixes https://github.com/amannn/next-intl/issues/454 Fixes https://github.com/amannn/next-intl/issues/1268

vercel[bot] commented 1 month ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-intl-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 10, 2024 3:28pm
next-intl-example-app-router ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 10, 2024 3:28pm
next-intl-example-app-router-without-i18n-routing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 10, 2024 3:28pm