Description
Hello!
I didn't initially notice that all the examples in the wiki and the example project for @fluent/react
use non-text nodes as direct children of <Localized>
, so I was implementing most of my localized content using text nodes instead:
<Localized id="foo">Placeholder text for foo</Localized>
This stopped working when I made use of the elems
option:
// jsx
<Localized
id="foo"
elems={{ score: <span className="score"></span> }}
vars={{ score: 1 }}>
Placeholder text for score
</Localized>
// ftl
foo = Here's a styled score: <score>{$score}</score>
The above outputs the string Here's a styled score: <score>1</score>
Wrapping the children of <Localized>
in an element fixes it:
// jsx
<Localized
id="foo"
elems={{ score: <span className="score"></span> }}
vars={{ score: 1 }}>
<span>Placeholder text for score</span>
</Localized>
The above outputs the HTML Here's a styled score: <span class="score">1</span>
, as expected.
Should I always ensure to include a HTML element inside <Localized>
, or is this only an issue with elems
? I also remember seeing an example somewhere with no placeholder text at all, just an empty tag: <Localized><span></span></Localized>
, making me think the tag is indeed always required.
Is there a convention/stance on usage here?
Thanks!