question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to handle HTML characters and codes, tags?

See original GitHub issue

Is there are any way to use html characters into translations? Similar to react-intl <FormattedHTMLMessage />

React makes it&nbsp;painless to&nbsp;create interactive UIs.<br />
Design simple views for each state in&nbsp;your application, and React will efficiently update and render just the right components when your data changes.

Thanks.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ignatevdevcommented, Dec 2, 2018

For anyone stumbling upon this, you can put your html characters or codes into translations, but to make them work you have to insert the text as dangerouslySetInnerHTML, like:

<Name
    dangerouslySetInnerHTML={{
        __html: i18n._('myString')
    }}
/>

This will work, but be cautious not to interpolate user input into such translations, as it would open a potential XSS vulnerability

1reaction
tricoder42commented, Nov 20, 2018

It’s possible to use HTML entities in translations, but the problem is that they’re converted to characters.

This is already fixed in https://github.com/lingui/js-lingui/issues/268, which preserves HTML entities in messages.

Tags are supported out of the box. Just wrap your message in <Trans> macro.

<Trans>
React makes it&nbsp;painless to&nbsp;create interactive UIs.<br />
Design simple views for each state in&nbsp;your application, and React will efficiently update and render just the right components when your data changes.
</Trans>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Guide to: Using HTML Tags/Characters in Labels
Since CML labels do not accept HTML Tags, you will need to use "escape characters". In this article we will explain escape characters...
Read more >
HTML Character Codes »
HTML character references add reserved and special characters to an HTML document. Learn how to use character entity codes.
Read more >
HTML codes and HTML special characters: The complete list
Character Entity name Entity number Hex Code Description A A &#65 &#x41 Capital A a a &#97 &#x61 Lowercase A À &Agrave &#192 &#xC0 Capital A‑grave...
Read more >
Special Characters in HTML - Tutorial - TeachUcomp, Inc.
To add special characters in HTML, type an ampersand (&), followed by the pound sign (#), followed by the number of the code,...
Read more >
HTML Symbols - W3Schools
To add such symbols to an HTML page, you can use the entity name or the entity number (a decimal or a hexadecimal...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found