amannn / next-intl

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

There is an issue in the defaultLocale #966

Closed Mood-al closed 7 months ago

Mood-al commented 7 months ago

Description

Hello, I set the middleware up and put the Arabic as the defaultLocale like so : `import createMiddleware from "next-intl/middleware";

export default createMiddleware({ // A list of all locales that are supported locales: ["en", "de", "ar"],

// Used when no locale matches defaultLocale: "ar", });

export const config = { // Match only internationalized pathnames matcher: ["/", "/(ar|de|en)/:path*"], };`

but when i try to go to http://localhost:3000 it always redirects me to http://localhost:3000/de. So how i can set the defaultLocale?

NOTE: this happen always when i add more than two locales, two locales work just fine!

Verifications

Mandatory reproduction URL

https://github.com/Mood-al/next-intl-bug-repro-app-router

Reproduction description

As you see in the website https://next-intl-bug-repro-app-router-lemon.vercel.app/ when you try to go there it redirects you directly to /de but the defaultLocale is ar! I have noticed that this happen just when there are more than 3 locales like my case ["en", "ar", "de"]. but when we have just 2 locales it works just fine!

Expected behaviour

next-intl should except more than 2 locales!

amannn commented 7 months ago

There might be a misunderstanding about what the defaultLocale is. Please carefully review the middleware docs to learn more. You probably have German configured as your primary language in your browser settings, that's why you're seeing a redirect to /de.

You can test that the Arabic locale works as the default like this:

curl -v 'https://next-intl-bug-repro-app-router-lemon.vercel.app/'
< HTTP/2 307 
(...)
< location: /ar