'How to use &nbsb; in react-intl
How can you use
when using react-intl so control word breaking.
I have a message like Rs. 100,00,000 but it is breaking on Rs.
is there anyway in can write the message as Rs. 100,00,000
When I try doing that it displays the Rs. 100,00,000 when the html is rendered
Solution 1:[1]
I've put unicode character \u00a0
just into the text message which suddenly worked :)
Text message: 'Please provide additional information like server logs'
Message with non breaking space: 'Please provide additional information like server\u00a0logs'
Solution 2:[2]
Solution 3:[3]
Not sure if it is good practice to coupling breaking logic with the message (although it is sometimes necessary). In most cases, this might require additional communication later with translators as they are usually unfamiliar with coding practices.
Also, number, currency, and date formatting are not the same in all languages. In case you are striving for perfectionism, maybe you should format these values as well.
If this breaking rule is the same in all your languages, maybe wrapping the localization message with the div
and setting the white-space: nowrap
is a cleaner solution.
<div style={{ whiteSpace: "nowrap" }}>
{message}
</div>
Alternatively, you can pass the HTML entity as a placeholder.
// "message.example": "Rs.{nbsp}100,00,000"
<FormattedMessage id="message.example" values={{ nbsp: <> </> }} />
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Agiltrue |
Solution 2 | Qais Palekar |
Solution 3 |