-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
How to interpolate JSX? #177
Comments
I just found #166 which talks about |
Hi, @dimaqq! const userName = <span>xxx</span>
jt`User ${ username } not found` const continueLink = <a href="">{t`continue`}</a>;
jt`${continueLink} to blah blah` Does it work for you? |
it would be nice if we could inline jsx in a I'm aware of the example you have above but was hoping there was a way to do this without having to extract the strong out of the JSX.
any thoughts on this? I can do a PR if you have thoughts on if this is feasible. lingui has this ability with as you can imagine the jsx might be part of a much bigger JSX, so having to move a simple 'strong' up out of the JSX it lives in could make things a bit harder to read. thx in advance! |
Hi @benmonro! So, for now you have an option to extract and use this with <div>{jt`${ <strong>${ jt`oh no` }</strong>} you did something wrong`}</div> ttag update --numberedExpressions=true your.po index.jsx Does it work for you? |
@AlexMost unfortunately not. The "oh no" doesn't get put into the .PO file and frankly it adds a lot of syntax. In that other thread there was a suggestion for a custom component for cases like this. I'd be happy to open a PR of you would be ok with a syntax like: Thoughts? |
My 2c: markup in translations is a complex problemToday you might have Tomorrow you'll have: const Strong = styled.span`...`;
... return <T><Strong>Please</Strong>don't</T>; and what then? simpler use casesI often find myself writing stuff like At the same time, if it were fully automatic, what would be the boundaries for translatable text or atoms of translatable text in Wrt. syntax, the ES6 template literals are probably the most powerful mechanism there is, as nesting, expressions, etc are all allowed. In fact the power is even a bit too much for |
@dimaqq 100% agree. Markup is a code, that can be broken by translator. It would be difficult to support that code inside locale files. Also it can be used to inject some XSS. So, ttag was designed in a way to avoid these troubles. @benmonro, we were investigating at this some time ago #3. And decided that if we want some kind of |
That seems like a bug, will create a ticket for that. |
Kinda related to #93,
How do I localise:
User %s not found
where %s is meant to expand to<span>xxx</span>
, orPlease <a href="...">continue</a> to blah blah
?I was thinking that for 1.
t
could perhaps return a fragment?For 2. I can't even think of a good syntax to express that both
please
andcontinue
are to be translated...The text was updated successfully, but these errors were encountered: