-
Notifications
You must be signed in to change notification settings - Fork 122
Cannot use backslash('\') in jsx value string #13
Comments
It's non-obvious because of how the string is first processed, but you need four backslashes: <FormattedMessage id="someId" defaultMessage="My message (one\\\\two\\\\three)"/> That said, I believe there is a bug here that I can fix in this plugin. The default message strings will be processed as part of the extraction process and end up with the following value in the JSON file: [
{
"id": "someId",
"defaultMessage": "My message (one\\two\\three)"
}
] While the message left in the source file will still contain the four backslashes. This could mean that when falling back to the default message in source (because the translation wasn't loaded or passed in to |
I also realized that I haven't released |
@ikhilko Thanks again for pointing this out. I spent a good part of the day revamping how backslash-escaping works for extracting messages, and it's now corrected. I've released |
|
Sounds good! Thank you |
@ericf, i have a question again... I'm just checked out
My expectations was that plugin will do it like JS do.
Please, can you correct me? |
@ikhilko In JavaScript strings: This then extends into how to tell the parser not to interpret Strings defined in JSX are parsed like HTML/XML strings, not JavaScript strings; this means they are double-escaped. Depending on which string you're creating (JavaScript or JSX) you need a different amount of backslashes. Using JSX Strings: <FormattedMessage id="someId" defaultMessage="one \\ two" /> When the JSX string Using JavaScript Strings: <FormattedMessage id="someId" defaultMessage={"one \\\\ two"} /> I hope this makes some sense as to why we're doing escape sequences this way for ICU Message strings. Also I just released an updated React Intl which uses the latest version of |
Thanks, you for detailed explanation of how it work. Now it more clear for me. |
@ericf Thank you very much for your answer. I am having a problem that may be related: I have posted a question on stackoverflow here with the details. I have inlined the question into this comment as well. Thank you in advance for any assistance. Summary
Details I am using I am bundling my app using Webpack / Babel. I have no Babel / react-intl specific config in my When I load my app using Webpack Dev Server, my messages show up fine: For what it is worth, I have tried using JSX strings, JS strings, using 1, 2, and 4 Any tips or suggestions are greatly appreciated. Thank you. Code samples An example of how I define messages
An example of how I might render my messages
Another example, which also does not work
Yet another failing example:
|
When I'm trying to use backslash in my values (defaultMessage) in JSX, like this:
Plugin raises:
So it's looks like I cannot use \ symbol in JSX value. Any suggestions?
The text was updated successfully, but these errors were encountered: