【发布时间】:2022-12-26 19:55:08
【问题描述】:
I have a project where users can provide a text for searching. This text CAN be HTML, and because of it, we won't escape it, as in the source, it is not escaped.
We provide a whole bunch of functionality, including deleting not needed searches.
We support many languages (including Japanese, among others), and therefore we cannot decide upfront in which place in translation the search we want to delete will be placed. So we use Trans component. And here the problem starts.
React itself handles HTML strings quite well. It just displays source code <a href="example.com">link</a>. But Trans interprets HTML (and displays link) or escapes HTML and displays &lt;a href="example.com"&gt;link&lt;/a&gt;.
I tried changing options (like escapeValue) or manually working with the string, which is passed as a value to translation. Nothing works as expected.
Is there any way to force Trans to behave as a react component and display HTML source code?
【问题讨论】:
-
If you want to display HTML source code as formatted text, take a look at Reacts
dangerouslySetInnerHTMLreactjs.org/docs/dom-elements.html -
and how to use it with
Transcomponent of i18next ? -
Please provide a code sn-p of your problem.
-
codesandbox.io/s/cool-snowflake-17k3xq I want only a variable named
htmlValueto be displayed as it was provided
标签: html reactjs i18next react-i18next