You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import { createIntlMiddleware } from 'next-intl/server';
// This middleware intercepts requests to `/` and will redirect
// to the best matching locale instead (e.g. `/en`). A cookie
// is set in the background, so if the user switches to a new
// language, this will take precedence from now on.
export default createIntlMiddleware({
locales: ['en', 'es'],
defaultLocale: 'en',
});
Mandatory reproduction URL (CodeSandbox or GitHub repository)
Do you know the accept-language header that Chrome sends in your case? I just tried setting the location to "Berlin" which assigns de-DE to the accept-language header.
There's currently a small bug in the middleware in the stable release, where "de-DE" is not resolved to "de", but instead a fallback to "en" is used.
If you use the "de" locale though, the middleware works:
curl 'https://csb-k2ien9-7ytkomg4x-amann.vercel.app' -H 'accept-language: de;q=0.8'
Redirecting to /de (307)
In next-intl@2.13.0-beta.2 this is already fixed, so you should be able to avoid this bug by using that version. I'll look into backporting some middleware improvements from #149 to stable though, so this fix is also available there.
Syncs various improvements from #149 to the main branch.
**Features**
- Add domain-based routing for middleware
- Add `localePrefix` option for middleware
- Add `localeDetection: false` flag for middleware
- Set alternate links in middleware (and add opt-out via
`alternateLinks: false`)
- `NextIntlClientProvider` now accepts `now` as an ISO 8601 date string
additionally
**Bugfixes**
- Handle locale subtags correctly when negotiating a locale in the
middleware (e.g. `de-DE` → `de` when only `de` is configured)
**Deprecations**
- Deprecate `import {createIntlMiddleware} from 'next-intl/server'` in
favor of `import createMiddleware from 'next-intl/middleware'`
- Deprecate `import {NextIntlClientProvider} from 'next-intl/client'` in
favour of `import {NextIntlClientProvider} from 'next-intl'`. As part of
this, add a matcher (see the updated docs).
**Docs**
- Add docs for new features
- Middleware should only be applied for localized pages
**Internal changes**
- Clean up examples
- Use latest metadata API from Next.js
- Upgrade Next.js
- Add sitemap for website
- Add docs for new features
Closes#237
Description
Hey i am trying to follow this demo app
https://github.com/amannn/next-intl/tree/main/packages/example-next-13
The point is that in my app and in demo page https://csb-k2ien9-7ytkomg4x-amann.vercel.app/en
If you change Language in Chrome settings for example to German, it will open /en anyway. Same for other Languages.
so this middleware doesn't work?
Mandatory reproduction URL (CodeSandbox or GitHub repository)
https://github.com/amannn/next-intl/tree/main/packages/example-next-13
Reproduction description
Steps to reproduce:
Expected behaviour
See another language in domain
for example
/es
The text was updated successfully, but these errors were encountered: