-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Trans renders tags in interpolation values as react elements #919
Comments
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 |
every child element in trans will be set if there is a <1> or whatever index there i - the above only applies to tags inside the translation string (like |
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 react-i18next@10.12.2 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
renders as
Seems like 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] While 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) |
closing this for now....looking forward to an eventual PR |
@kiborrdis, @jamuhl, for posterity: The workaround I found was to create a passthrough component that outputs the value: function Passthrough({ text }) {
return text;
} resources: {
key: 'Output: <0 />'
} const italicText = '<i>italics</i>';
<Trans i18nKey="key">
<Passthrough text={italicText} />
</Trans> Result:
|
I'm not sure if it's a bug or expected behavior, didnt find definitive answer in docs and issues.
Describe the bug
Trans
renders tags in interpolation values as react elements instead of strings(if flagtransSupportBasicHtmlNodes
is set totrue
of course)If
transSupportBasicHtmlNodes
is set tofalse
, value with html tags fails to render as string also, and react elements matching tags is not rendered.Occurs in react-i18next version
10.11.5
To Reproduce
Reproduction based on example from docs: https://codesandbox.io/s/react-i18next-qlwhe?fontsize=14
To check behavior with
transSupportBasicHtmlNodes: false
, change it's value ini18n.js
Expected behaviour
Tags in interpolation values are being ignored and rendered as strings with
transSupportBasicHtmlNodes
set to either true or falseThe text was updated successfully, but these errors were encountered: