Skip to content

localePrefix doesn't support "es-US" prefixed locale #1329

Description

@karolkarolka

Description

While implementing the prefixes for [locale] segment, I've found that the es-US locale (and probably other unsupported ISO 639-1 standard language codes locales, tho es-US is widely used) can't be prefixed. The routing object with supported locales and prefixes specified as localePrefix will respond with 404 in the middleware setup. Other defined locales in the config will be fine, they will be prefixed and server will respond with 200 HTTP code, except for es-US. It seems like it is replaced with the nearest ISO standard lang code resolved for the build environment. In this case, the response's NEXT_LOCALE cookie header will resolve to es-US -> en-US, which is wrong, I should be able to prefix all locales specified in my next-intl config. I believe createIntlMiddleware(routing) needs to be patched.

Verifications

  • I've verified that the problem I'm experiencing isn't covered in the docs.
  • I've searched for similar, existing issues on GitHub and Stack Overflow.
  • I've compared my app to a working example to look for differences.

Mandatory reproduction URL

https://github.com/karolkarolka/next-intl-es-us-prefix-bug

Reproduction description

Steps to reproduce:

  1. Open reproduction
  2. Navigate to /us/es
  3. The server will respond with GET /us/es 404

Expected behaviour

Expected behaviour:
es-US locale should be prefixed with /us/es. locale in getRequestConfig(async ({ locale }) should be es-US. The path /es/us should resolve to / home directory.

Actual behaviour:
es-US locale cannot be prefixed properly. locale in getRequestConfig(async ({ locale }) isen-US. The path /es/usresolves to 404 not found.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions