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

Does not parse plural default values from Trans component #580

Open
addiebarron opened this issue May 27, 2022 · 2 comments
Open

Does not parse plural default values from Trans component #580

addiebarron opened this issue May 27, 2022 · 2 comments
Labels

Comments

@addiebarron
Copy link

Parser does not parse plural default values when using the Trans component

When generating translation files, the parser does not generate the default English string values for plurals when using the Trans component. The parser does work this way when using t.

To Reproduce

Use a Trans component with a defaultValue_plural passed into tOptions (this example uses JSON v3 plural rules).

const numCount = condition ? 1 : 3;
return (
  <Trans t={t} count={numCount} tOptions={{
      defaultValue_plural: "<1>Plural</1> default value"
    }}> 
    <strong>Singular</strong> default value
  </Trans>
)

Expected behavior

With the above example, the following JSON is generated:

{
  "<1>Singular</1> default value": "<1>Singular</1> default value",
  "<1>Singular</1> default value_plural": "<1>Singular</1> default value"
}

I would expect this result:

{
  "<1>Singular</1> default value": "<1>Singular</1> default value",
  "<1>Singular</1> default value_plural": "<1>Plural</1> default value"
}

When defaultValue_plural is passed into the options of a t call, the parser picks this up and inserts it into the translation JSON at the correct plural key. I would expect the same to happen with the Trans component, but it doesn't seem to. The behavior should be consistent with the Trans component.

In general I'd like to see better support for Trans with default values and plurals, though that may be in the court of the main i18next package. If anyone has any workaround suggestions (besides manually editing the JSON in this case), I'd love to hear it.

Your Environment

  • runtime version: node v16
  • i18next version: 21.6.4
  • os: Mac
@karellm
Copy link
Member

karellm commented May 28, 2022

Would you be interested in making a PR for this?

@karellm karellm added the Bug label May 28, 2022
@crazyyi
Copy link

crazyyi commented Mar 20, 2023

I tried t function and couldn't get the correct plurals either. It would always produce the defaultValue no matter what I put in defaultValue_plural.

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

No branches or pull requests

3 participants