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
Version 21.6.4 breaks interpolation #1721
Comments
Yes, this is expected, since If you still wish the old behaviour, you need to pass |
Thanks @adrai! Although you can see this behaviour has been working as expected until 21.6.4, any prior 21.x.x release didn't break it |
Yes, this was an error on previous versions |
tldr; since v21.0.0 this was an error, and it was fixed in v21.6.4 |
@adrai I recently ran into this issue as well. It feels to me like the intuitive behaviour is to hide the interpolation marker, i.e. I'm guessing the change was done due to security implications, but would there be any possibility to still hide the variables if they are not sent to the t function with |
With v21.6.8 you can now pass in individual skipOnVariables option for the t function: // resourceKey: "welcome": "{{ foo }}",
console.log(i18next.t('welcome', { foo: 'hi' })) // logs: "hi"
console.log(i18next.t('welcome', { foo: '' })) // logs: ""
console.log(i18next.t('welcome', { foo: null })) // logs: ""
console.log(i18next.t('welcome', { foo: undefined })) // logs: ""
console.log(i18next.t('welcome', {})) // logs: "{{ foo }}"
console.log(i18next.t('welcome', { interpolation: { skipOnVariables: false } })) // logs: "" |
Those were interesting reads, and I definitely see the use of the option from reading #1479. I don't think that necessarily has to change your console log statement 4 and 5. In the latest version, with your example, passing I also don't see why fixing the recursive behaviour with This is what I would expect with the defaults in the latest 21.X.X version. (see sandbox here to observe passing // resourceKey: "welcome": "{{ foo }}", "nested": "smurf"
console.log(i18next.t('welcome', { foo: 'hi' })) // logs: "hi"
console.log(i18next.t('welcome', { foo: '' })) // logs: ""
console.log(i18next.t('welcome', { foo: null })) // logs: ""
console.log(i18next.t('welcome', { foo: undefined })) // logs: "" => currently displays "{{ foo }}" as of 21.6.7
console.log(i18next.t('welcome', {})) // logs: "" => currently displays "{{ foo }}" as of 21.6.7
console.log(i18next.t('welcome', { foo: '$t(nested)' })) // logs: "$t(nested)"
console.log(i18next.t('welcome', { interpolation: { skipOnVariables: false } })) // logs: ""
console.log(i18next.t('welcome', { foo: '$t(nested)', interpolation: { skipOnVariables: false }})) // logs: "smurf" |
You're not using v21.6.8 in the sandbox yet. |
Yeah, good point! Then the only thing that should still be odd (to me) would be the 5'th log where I would expect this behavior to make it work like it used to with console.log(i18next.t('welcome', {})) // logs: "{{ foo }}" as of 21.6.8 => my expectation: ""
console.log(i18next.t('welcome')) // logs: "{{ foo }}" as of 21.6.8 => my expectation: "" Or am I going crazy? :D |
No, this will not change, I'm sorry. |
Ok! Fair enough, if it is intended behavior then I'll work around it. The fix with undefined really helped though! Thank you for that quick fix :) |
Might still be a bug when passing skipOnVariables in the t function: https://codesandbox.io/s/react-i18next-forked-j817j?file=/src/app.js Passing (I should be on latest as undefined behavior works as expected) |
Yep, $t() usage was missing. v21.6.9 is better ;-) |
Since version 21.6.4, translations with undefined variables print unescaped strings from the translations file. This behaviour was not observed in version 21.6.3 and hasn't been fixed since 21.6.4.
To Reproduce
See CodeSandbox. Change
i18next
version to21.6.3
and observe the string{{ foo }}
disappears which is the correct behaviour.Expected behavior
The translation string is not printed, i.e. we print an empty string
Your Environment
The text was updated successfully, but these errors were encountered: