amannn / next-intl

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

fix: Handle overlapping custom locale prefixes correctly #1343

Closed amannn closed 2 months ago

amannn commented 2 months ago

Consider this config:

export const routing = defineRouting({
  locales: ["en-US", "es-US"],
  defaultLocale: "en-US",
  localePrefix: {
    mode: "always",
    prefixes: {
      "es-US": "/us/es",
      "en-US": "/us"
    },
  }
});

… a pathname like /us/es would previously be incorrectly rewritten to /en-US/es internally. With this change, we now prioritize more specific prefixes in order to rewrite this request correctly to /es-US.

Fixes #1329

vercel[bot] commented 2 months 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 Sep 17, 2024 9:13am
next-intl-example-app-router ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 17, 2024 9:13am
next-intl-example-app-router-without-i18n-routing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 17, 2024 9:13am