react-i18next
react-i18next copied to clipboard
Phrase response with \\n
🐛 Bug Report
The problem with the returned string via the Phrase. The expected result of the response is a string with special characters that were in the string when sending.
The result is a string with broken special characters such as \n.
expect => get
some\nstring => some\\nstring


react does not know \n use
https://react.i18next.com/latest/trans-component#usage-with-simple-html-elements-like-less-than-br-greater-than-and-others-v10.4.0
Problem with Phrase + Trans. If translations come with Phrase, then Trans shows the translation character, but should break the line
Can you create a reproducible example with based on something like: https://github.com/i18next/react-i18next/tree/master/example/react-native
btw: this may help: https://stackoverflow.com/a/69436906/1859027
It's not react-i18next that does this. It's more or less a quirk in react-native...@adrai's provided link and the accepted answer there shows it https://stackoverflow.com/a/32480141/923356 even more the comment
If the text comes from a prop, make sure you pass it like this:
<Component text={"Line1\nLine2"} />instead of<Component text="Line1\nLine2" />(notice the added curly braces)
@adrai
btw: this may help: https://stackoverflow.com/a/69436906/1859027
This is the solution I used:

I abandoned the Trans component for the following reasons:
- translations with line breaks need to be formatted
- It is impossible to pass a formatted string to Trans because the t() function returns a value without double curly brackets: expectation - <>{{email}}</> result - <></>
@jamuhl
It's not react-i18next that does this. It's more or less a quirk in react-native...@adrai's provided link and the accepted answer there shows it https://stackoverflow.com/a/32480141/923356 even more the comment
If the text comes from a prop, make sure you pass it like this:
<Component text={"Line1\nLine2"} />instead of<Component text="Line1\nLine2" />(notice the added curly braces)
Not worked for me
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.