-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@fluent/react – does/should <Localized> work with a text node as a direct child? #498
Comments
Ah, good questions :) This looks like it's a mix of two related issues:
For the first issue, I've been meaning to file an issue about separating For the second issue, we could fix it in the current code because we return a React fragment anyways; we're free to add elements into it even if the original copy was a simple string. This would also be beneficial in the future when/if we allow translations to add markup even if |
Thanks, that clears it up for me!
Yes, that sounds nice to me too!
That sounds good in theory, but I can imagine some confusion in combination with |
Hmm, good point about the expectation of I understand that the other option to fix the confusion is to forbid HTML output from |
Perhaps if the allowed markup includes only text-level tags, Would that list of tags strictly include only plain tags without attributes, or would localizers also be able to make use of classes etc? I imagine if I wanted a fragment to include something like Even if translators wouldn't be doing this deliberately (can't think of why they would 😬 😄 ), I think it'd still make me uneasy knowing developers have the option to add quick hacks and stuff on the Fluent level where things should really be addressed on the source code level. But I do agree with the sentiment that text-level semantic elements should be possible regardless of the choice of |
The way this works in In React, I made a decision a long time ago to not use Also, |
How about this?
|
That all sounds good to me! Thank you for the background info, very interesting getting a look into how this API is evolving :) |
A quick update: I have a draft PR open which fails a few tests currently. I'll try to fix them tomorrow and write some new tests. @elisehein would you be intersted in giving me feedback on the PR and reviewing it when it's ready? |
@stasm Sure! |
Hi, just popping in to make a note that I ran into this same issue, in case more real-world examples are useful. It was rather surprising to encounter my markup as a literal string without any processing, for no clear reason! A simplified version of my case is the following: login-text-continue = To continue, please login below. If you don't have an account yet, you should <register>register</register> one! <Localized id="login-text-continue" elems={{ register: <a href="/register" /> }}>
(Placeholder text for instructing the user to login or register)
</Localized> In this case, I'm trying to avoid duplicating localized strings into the source code, instead using the placeholder text as an instruction to the developer. Because the placeholder text does not contain markup, This should probably at least be explicitly documented ("make sure that you include some kind of HTML/React element in the placeholder string!"). Though a fix is better, of course :) Edit: Actually, it turns out that replacing the placeholder text with text that contains inline markup, breaks too; with the |
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:This stopped working when I made use of the
elems
option:The above outputs the string
Here's a styled score: <score>1</score>
Wrapping the children of
<Localized>
in an element fixes it: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 withelems
? 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!
The text was updated successfully, but these errors were encountered: