Closed karolkarolka closed 2 months ago
Thanks for the report! I can confirm the issue and have found that this is caused by the overlapping /us
segment. If /us/es
is requested, then the /us
prefix matches and the actual pathname that's called internally is /en-US/es
.
This is definitely a bug, we need to support matching more specific prefixes in case there's an overlap.
I'll look into this, should hopefully have a fix this week!
Hmm, I had a first shot at this in https://github.com/amannn/next-intl/pull/1343, but it seems like there's still a piece missing. Having a second look, can't be much …
Ok, it's fixed now in next-intl@3.19.3
✌️
Thanks @amannn 👌🏽
Description
While implementing the prefixes for
[locale]
segment, I've found that thees-US
locale (and probably other unsupported ISO 639-1 standard language codes locales, thoes-US
is widely used) can't be prefixed. Therouting
object with supportedlocales
andprefixes
specified aslocalePrefix
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 fores-US
. It seems like it is replaced with the nearest ISO standard lang code resolved for the build environment. In this case, the response'sNEXT_LOCALE
cookie header will resolve toes-US
->en-US
, which is wrong, I should be able to prefix all locales specified in mynext-intl
config. I believecreateIntlMiddleware(routing)
needs to be patched.Verifications
Mandatory reproduction URL
https://github.com/karolkarolka/next-intl-es-us-prefix-bug
Reproduction description
Steps to reproduce:
/us/es
GET /us/es 404
Expected behaviour
Expected behaviour:
es-US
locale should be prefixed with/us/es
.locale
ingetRequestConfig(async ({ locale })
should bees-US
. The path/es/us
should resolve to/
home directory.Actual behaviour:
es-US
locale cannot be prefixed properly.locale
ingetRequestConfig(async ({ locale })
isen-US
. The path/es/us
resolves to 404 not found.