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

Number vars passed as Trans children are not processed correctly #1754

Closed
vasiliy-l opened this issue May 22, 2024 · 1 comment
Closed

Number vars passed as Trans children are not processed correctly #1754

vasiliy-l opened this issue May 22, 2024 · 1 comment

Comments

@vasiliy-l
Copy link

🐛 Bug Report

When passing number translation vars as children of <Trans> component, the values cannot be properly formatted.
Then passing the values as vars prop of the component, the numbers are formatted as expected.

The bug appears in react-i18next version 14.0.7 and above. Probably, related to the fixes for #1729

To Reproduce

https://codesandbox.io/p/sandbox/react18next-trans-child-number-vars-not-formatted-cdx4f2

i18n.use(initReactI18next).init({
  resources: {
    en: {
      translation: {
        "trans-key-with-number-var": "Treat value as number: {{foo, number}}",
      },
    },
  },
 // ...
});

...

<Trans t={t} i18nKey="trans-key-with-number-var" values={{ foo: 1234 }} />
// OK
// > Treat value as number: 1,234

<Trans t={t} i18nKey="trans-key-with-number-var">
   {{ foo: 1234 }}
</Trans>
// Number value cannot be parsed properly:
// > Treat value as number: NaN

Expected behavior

Values passed as <Trans> children are expected to be formatted properly.

Your Environment

  • i18next version: i.e. 23.11.5
  • react-i18next version: 14.0.7
@adrai adrai closed this as completed in 29c7794 May 22, 2024
@adrai
Copy link
Member

adrai commented May 22, 2024

@stefan-schweiger unfortunately @vasiliy-l is right...
I've now released v14.1.2 that may work for both use cases... but if this gets issues in future, we need to revert #1729 completely

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

No branches or pull requests

2 participants