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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

defaultValues of pluralized messages are not being sent to missingKeyHandler properly #1703

Closed
hon2a opened this issue Dec 7, 2021 · 1 comment 路 Fixed by #1704
Closed

defaultValues of pluralized messages are not being sent to missingKeyHandler properly #1703

hon2a opened this issue Dec 7, 2021 · 1 comment 路 Fixed by #1704

Comments

@hon2a
Copy link
Contributor

@hon2a hon2a commented Dec 7, 2021

Please note that there's a similar report in #1549, but a different aspect is observed there and eventually fixed.

馃悰 Bug Report

The "save missing" feature doesn't work properly for pluralized messages - it calls the missingKeyHandler (or backendConnector.saveMissing) once for every plural form, but passes the same default value to all even if there are proper default values per plural form defined in translation call options.

Steps

Using the following init options

{
    fallbackLng: "en",
    saveMissing: true,
    saveMissingPlurals: true,
    missingKeyHandler: (_1, _2, key, defaultValue) => console.log({ key, defaultValue })
  }

call

t("firstMissing", {
  count: 1,
  defaultValue_one: "first singular",
  defaultValue_other: "first plural"
})
t("secondMissing", {
  count: 10,
  defaultValue_one: "second singular",
  defaultValue_other: "second plural"
})

Actual

The following is logged:

{key: "firstMissing_one", defaultValue: "first singular"}
{key: "firstMissing_other", defaultValue: "first singular"}
{key: "secondMissing_one", defaultValue: "second plural"}
{key: "secondMissing_other", defaultValue: "second plural"}

Expected

The following should be logged instead:

{key: "firstMissing_one", defaultValue: "first singular"}
{key: "firstMissing_other", defaultValue: "first plural"}
{key: "secondMissing_one", defaultValue: "second singular"}
{key: "secondMissing_other", defaultValue: "second plural"}

Notes

The above seems to be expected in the source code (note the "ignored" comment in test), but without any documentation or explanation.

To Reproduce

CodeSandbox demo (open console and observe the logged output)

Expected behavior

The pluralized default values, when provided (e.g. { default_one: 'singular', default_other: 'plural' }), should each be supplied to the missing key handling logic with the respective keys (see Expected section above). There's no sensible reason to use the "currently used" default (based on count) for all the plural forms.

Your Environment

  • runtime version: Google Chrome Version 96.0.4664.55 (Official Build) (x86_64)
  • i18next version: 21.5.5
  • os: Mac OS Monterey Version 12.0.1 (21A559)
@hon2a hon2a mentioned this issue Dec 7, 2021
3 tasks
@adrai
Copy link
Member

@adrai adrai commented Dec 7, 2021

thank you, released in v21.5.6

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.

2 participants