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

Missing key default pluralization issues #1549

Closed
namoscato opened this issue Feb 7, 2021 · 8 comments · Fixed by #1558
Closed

Missing key default pluralization issues #1549

namoscato opened this issue Feb 7, 2021 · 8 comments · Fixed by #1558

Comments

@namoscato
Copy link
Contributor

🐛 Bug Report

There seems to be some issues with default value pluralization when missingKeys is enabled:

  1. The result of interpolation is incorrect and does not seem to respect pluralization
  2. The singular and plural values passed to the backend, when configured, are the same

To Reproduce

Here's a CodeSandbox that illustrates the issue when evaluating:

t("myMissingKey", {
    count,
    defaultValue: "{{ count }} word",
    defaultValue_plural: "{{ count }} words"
})

This is not an issue when saveMissing=false.

Expected behavior

Per the defaultValue description:

you also can define defaults for plurals by adding defaultValue_plural / defaultValue_2 -> _suffix depends on same pluralrules

I would expect the myMissingKey string to be pluralized correctly as count changes, and the missing key handler configured via a backend, should receive:

{
    "myMissingKey": "{{ count }} word",
    "myMissingKey_plural": "{{ count }} words"
}

Your Environment

  • runtime version: Chrome v88
  • i18next version: v19.8.7
  • react-i18next version: v11.8.5
  • i18next-locize-backend version: v4.1.9
  • os: macOS
@adrai
Copy link
Member

adrai commented Feb 8, 2021

This is probably, because your first count value is 0, and this is a plural

@namoscato
Copy link
Contributor Author

Yeah, makes sense – if the state is initialized to 1, it's always singular.

With that said, is this expected behavior?

@adrai
Copy link
Member

adrai commented Feb 8, 2021

seems so

@stale
Copy link

stale bot commented Feb 15, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 15, 2021
@namoscato
Copy link
Contributor Author

Working with this some more over the past week, this still seems like a minor bug to me.

I'm happy to help out with a fix, but it might be a few weeks before I get around to it; feel free to point me in the right direction of the relevant code in the meantime.

@stale stale bot removed the stale label Feb 15, 2021
@jamuhl
Copy link
Member

jamuhl commented Feb 15, 2021

@namoscato that functionality can be found here https://github.com/i18next/i18next/blob/master/src/Translator.js#L245

would be happy to accept a PR

namoscato added a commit to namoscato/i18next that referenced this issue Feb 19, 2021
@stale
Copy link

stale bot commented Feb 22, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 22, 2021
@namoscato
Copy link
Contributor Author

FYI, I took a pass at this in #1558.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants