Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Trans renders tags in interpolation values as react elements #919
I'm not sure if it's a bug or expected behavior, didnt find definitive answer in docs and issues.
Describe the bug
Occurs in react-i18next version
To check behavior with
if set true it's expected for: https://github.com/i18next/react-i18next/blob/master/src/context.js#L9 that replace in interpolation happens before converting to react-elements
If this parameter designed to describe tags in translation strings to replace with react elements, then it's not working right since in codesandbox above it renders
Yes. But problem i am trying to describe is not connected with
Sorry if my explanation is vague, or problem trivial, but i do not see sane workaround for now
I'll try to explain again:
If i do(with
Can you retry with email@example.com it should check for https://github.com/i18next/react-i18next/blob/master/src/context.js#L9 allowed tags
Yup that made things better. Sorry i havent figured out version bump myself, for some reason i thought i using the last one, will try to avoid that mistake in the future.
Unfortunately there is still some unexpected behaviour
We can simplify
also if we do
it renders as
With unwanted commas at the start and the end, and between
The first case:
I assume b tag is rendered as string (as the code should do) -> still the inner Elements get transformed returning node children -> node children toString --> [object Object]
The second case:
Currently, at least this is fixed regarding security concerns...not fixed is interpolating tags into content - but honestly, I'm not sure we can support that...won't be easy.
Do you really need to interpolate
First of all, i solved my use case(displaying user input bold in translation string) via updating
it's works relatively fine for me
I reported additional bugs just for the sake of informing about their existance, since i came across them. I mean, i can live with them fine.
Some thoughts about your what you said:
I can think of use case when you want to show some html tags as string. For example some html tutorial/example or whatever. So i'm not sure if it is neceserily wrong. On the other hand, you'd probably want
Yeah i understand. I can try to fix it and send PR if attempt end up successful. If it's fine of course
I really dont want to do such things :). But it bothers me that users can put some wild interpolation value here.
Anyway thank you for quick responses, help and your work on the such a great lib!
Sure PR's are always welcome...I will look into it too as soon I got more time - yet not absolutely sure how to approach it...(escaping interpolation and undo again after transforming to react or just adding a different handler for those cases processing the AST children to string)