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

error in interpolation when language is set to "en_US" #1694

Open
3 tasks done
yardz opened this issue Feb 2, 2025 · 3 comments · May be fixed by #1412
Open
3 tasks done

error in interpolation when language is set to "en_US" #1694

yardz opened this issue Feb 2, 2025 · 3 comments · May be fixed by #1412
Labels
bug Something isn't working unconfirmed Needs triage.

Comments

@yardz
Copy link

yardz commented Feb 2, 2025

Description

I'm trying to use next-intl but I run into a bug. My language is set to the "en_US" format. When we use the language in this format and try to do an interpolation, this error occurs: Error: INVALID_MESSAGE: Incorrect locale information provided

I reproduced the error in this repository:
https://github.com/yardz/example-app-router-without-i18n-routing--error

It only has 3 commits.
The first is a copy of the example example-app-router-without-i18n-routing (the base example: https://github.com/amannn/next-intl/tree/main/examples/example-app-router-without-i18n-routing).
The second commit is changing the name of the language files (even the second commit is working normally)
In the third commit I just add the variable for interpolation, then I start getting the error

Verifications

Mandatory reproduction URL

https://github.com/yardz/example-app-router-without-i18n-routing--error

Reproduction description

The quickest way to reproduce is:

Change the language files from "en" to "en_US" and "de" to "de_DE".
And make the necessary adjustments (this commit: yardz/example-app-router-without-i18n-routing--error@7d7c70a) ---- At this stage the example you provide is working normally ----

Then add a variable for interpolation (This commit: yardz/example-app-router-without-i18n-routing--error@b700d49)

Use this example as starting point: https://github.com/amannn/next-intl/tree/main/examples/example-app-router-without-i18n-routing

Expected behaviour

the interpolation works with file "en" but does not work with the pattern "en_US". I believe it should also work with the "en_US" pattern

@yardz yardz added bug Something isn't working unconfirmed Needs triage. labels Feb 2, 2025
@amannn
Copy link
Owner

amannn commented Feb 3, 2025

Locales should use - to separate a language and a region (e.g. en-US).

In v4, next-intl will warn early when an invalid locale is encountered.

@amannn amannn linked a pull request Feb 3, 2025 that will close this issue
8 tasks
@yardz
Copy link
Author

yardz commented Feb 3, 2025

@amannn I believe that's not why. All translations work with "_" (underscore) only interpolations do not work. If that were the case, all translations should stop working, right?

Image

I put a print. You can see that "Login" is working but the interpolation is not.

@amannn
Copy link
Owner

amannn commented Feb 4, 2025

In v3 the behavior is a bit inconsistent. Some features might still work which don't rely on the Intl API, but others will break.

The error you're seeing comes from the JavaScript runtime itself:

Image

In v4 I'll make it more obvious if you have an incorrect locale, so you don't run into this error down the road.

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

Successfully merging a pull request may close this issue.

2 participants