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

interpolated object undefined if any other values are passed to Trans #1801

Closed
literalpie opened this issue Sep 14, 2024 · 2 comments
Closed

Comments

@literalpie
Copy link

literalpie commented Sep 14, 2024

🐛 Bug Report

When alwaysFormat is set to true, and you use Trans with any count or values, the interpolated value of objects is undefined.

For example, this causes "value: undefined":

<Trans count={count}> 
  number: {'{{count, INTEGER}}'}
  <br />
  name: {{ name }}
</Trans>

but this works as expected:

<Trans> 
  name: {{ name }}
</Trans>

A workaround is to interpolate the value itself instead of an object:

<Trans count={count}> 
  number: {'{{count, INTEGER}}'}
  <br />
  name: { name }
</Trans>

To Reproduce

stackblitz with issue (react-i18next: 15.0.1)
stackblitz working as expected (react-i18next: ^13.0.0)

Expected behavior

The result should be: "number: (formatted 5) name: (formatted Ben)"
but the actual result is: "number: (formatted 5) name: (formatted undefined)":

Your Environment

  • runtime version: Safari and Chrome
  • i18next version: i.e. 23.15.1
  • os: Mac

I can reproduce in ^14.0.0 and 15.0.1, but not in ^13.0.0 (see stackblitz above).

We use react-i18next in a very large monorepo, so it would be difficult to find all instances of this issue to apply the simple workaround mentioned above.

@adrai
Copy link
Member

adrai commented Sep 14, 2024

hehe... you need to talk with @timwest612
it's because of this issue: #1719 and this change: 2c4c4a7

I've now tried to address also your case, but this gets trickier and trickier...
please try v15.0.2...

@adrai adrai closed this as completed Sep 14, 2024
@literalpie
Copy link
Author

Thank you so much!

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