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

other should be a fallback for missing values too #1337

Closed
3 tasks done
wingsofovnia opened this issue Sep 15, 2024 · 1 comment
Closed
3 tasks done

other should be a fallback for missing values too #1337

wingsofovnia opened this issue Sep 15, 2024 · 1 comment
Labels
bug Something isn't working unconfirmed Needs triage.

Comments

@wingsofovnia
Copy link

wingsofovnia commented Sep 15, 2024

Description

When interpolating enums or other grammar rules that have other fallback for unmatched values, it does not treat an undefined value as a mismatch, instead it fails to render the whole message.

Say we have such a message (from docs):

"message": "{gender, select, female {She} male {He} other {They}} is online."

The behaviour is:

t('message', {gender: 'female'});     // "She is online."
t('message', {gender: 'male'});       // "He is online."
t('message', {gender: 'something'});  // "They is online."
t('message', {gender: undefined});    // "They is online."

// but

t('message');     // "message" - fails to render
t('message', {}); // "message" - fails to render

I am not sure if that is intentional, but it neither looks consistent to me nor behaves as one might imply from the docs:

The other case is required and will be used when none of the specific values match.

Such behaviour is useful for creating plurals of the same thing:

const messages = {
  "elf": {
    "name": "{plural, select, y {elves} other {elf}}",
  }
}

t('elf.name')                  // "elf" - doesn't work now
t('elf.name', { plural: 'y' }) // "elves"

t('elf.name', { plural: 'f' }) // "elf" - only workable solution right now, too verbose

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

n/a

Reproduction description

see description

Expected behaviour

t('message');     // "They is online."
t('message', {}); // "They is online."
@wingsofovnia wingsofovnia added bug Something isn't working unconfirmed Needs triage. labels Sep 15, 2024
@amannn
Copy link
Owner

amannn commented Sep 16, 2024

We rely on the behavior of intl-messageformat here, which also doesn't provide a way for customizing this. Therefore this is out of scope for next-intl.

That being said, I agree with the behavior of intl-messageformat, enabling stricter checks while still allowing undefined to be passed for edge cases as a way to bypass the check.

@amannn amannn closed this as completed Sep 16, 2024
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

No branches or pull requests

2 participants