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

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

Closed
3 tasks done
karolkarolka opened this issue Sep 6, 2024 · 4 comments · Fixed by #1343 or #1344
Closed
3 tasks done

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

karolkarolka opened this issue Sep 6, 2024 · 4 comments · Fixed by #1343 or #1344
Labels
bug Something isn't working

Comments

@karolkarolka
Copy link

karolkarolka commented Sep 6, 2024

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.

@karolkarolka karolkarolka added bug Something isn't working unconfirmed Needs triage. labels Sep 6, 2024
@amannn
Copy link
Owner

amannn commented Sep 17, 2024

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!

@amannn
Copy link
Owner

amannn commented Sep 17, 2024

Hmm, I had a first shot at this in #1343, but it seems like there's still a piece missing. Having a second look, can't be much …

@amannn
Copy link
Owner

amannn commented Sep 17, 2024

Ok, it's fixed now in next-intl@3.19.3 ✌️

@karolkarolka
Copy link
Author

Thanks @amannn 👌🏽

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants