Skip to content
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

The demo app with next 13 not redirect automatically for locale. #237

Closed
DonikaV opened this issue Apr 11, 2023 · 1 comment · Fixed by #238
Closed

The demo app with next 13 not redirect automatically for locale. #237

DonikaV opened this issue Apr 11, 2023 · 1 comment · Fixed by #238
Labels
bug Something isn't working unconfirmed Needs triage.

Comments

@DonikaV
Copy link

DonikaV commented Apr 11, 2023

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?

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)

https://github.com/amannn/next-intl/tree/main/packages/example-next-13

Reproduction description

Steps to reproduce:

  1. Open demo site with German language selected in Chrome
  2. See always /en

Expected behaviour

See another language in domain
for example

/es

@DonikaV DonikaV added bug Something isn't working unconfirmed Needs triage. labels Apr 11, 2023
@amannn
Copy link
Owner

amannn commented Apr 11, 2023

Hey @DonikaV and thank you for the bug report!

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.

Screenshot 2023-04-11 at 15 41 45

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.

Thanks again!

amannn added a commit that referenced this issue Apr 12, 2023
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working unconfirmed Needs triage.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants