How to interpolate JSX?
See original GitHub issueKinda related to https://github.com/ttag-org/ttag/issues/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
and continue
are to be translated…
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
How can I interpolate JSX with an expression in a string?
Remember that everything between { and } is just Javascript, so the expression is 'total total-' + obj.state which is then set as...
Read more >Guide to String Interpolation With React
In this short guide, learn how to perform string interpolation with React and JavaScript, using the plus operator and template literals!
Read more >Understand and Use Interpolation in JSX
We'll learn that interpolation is not unique to JSX and we'll learn the limitations and capabilities of interpolation in JSX.
Read more >String Interpolation in React (with examples)
Use a template literal for string interpolation in React, e.g. <div className={ text-white ${myClass} }> . Template literals are delimited with backticks and ......
Read more >Interpolation in React - Learn tech systems
Interpolation is defined as “the insertion of something of a different nature into something else.” ; Result: ; So, everything that we put...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
My 2c:
markup in translations is a complex problem
Today you might have
<T><strong>Please</strong>do</T>
.Tomorrow you’ll have:
and what then?
simpler use cases
I often find myself writing stuff like
<label htmlFor=...>{t
Username}</label>...
and I wish there was some way to make that less verbose, somehow automatic.At the same time, if it were fully automatic, what would be the boundaries for translatable text or atoms of translatable text in
<a>foo<b>bar<c>baz</c></b>quux></a>
?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
ttag
and only constants are allowed in the${}
substitution blocks, which IMO is a good choice. I feel that anything else would require own babel plugin that parses superset of JSX, that should probably be a separate project.@benmonro
That seems like a bug, will create a ticket for that.