react-i18next icon indicating copy to clipboard operation
react-i18next copied to clipboard

Phrase response with \\n

Open gHashTag opened this issue 3 years ago • 7 comments
trafficstars

🐛 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

unknown-1

unknown-2

gHashTag avatar Jul 22 '22 18:07 gHashTag

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

adrai avatar Jul 22 '22 18:07 adrai

Problem with Phrase + Trans. If translations come with Phrase, then Trans shows the translation character, but should break the line

gHashTag avatar Jul 22 '22 19:07 gHashTag

Can you create a reproducible example with based on something like: https://github.com/i18next/react-i18next/tree/master/example/react-native

adrai avatar Jul 22 '22 19:07 adrai

btw: this may help: https://stackoverflow.com/a/69436906/1859027

adrai avatar Jul 22 '22 19:07 adrai

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)

jamuhl avatar Jul 22 '22 20:07 jamuhl

@adrai

btw: this may help: https://stackoverflow.com/a/69436906/1859027

This is the solution I used: image

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 - <></>

gHashTag avatar Jul 26 '22 16:07 gHashTag

@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

gHashTag avatar Jul 26 '22 16:07 gHashTag

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.

stale[bot] avatar Aug 11 '22 23:08 stale[bot]