question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to interpolate JSX?

See original GitHub issue

Kinda related to https://github.com/ttag-org/ttag/issues/93,

How do I localise:

  1. User %s not found where %s is meant to expand to <span>xxx</span>, or
  2. Please <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:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dimaqqcommented, Aug 2, 2019

My 2c:

markup in translations is a complex problem

Today you might have <T><strong>Please</strong>do</T>.

Tomorrow you’ll have:

const Strong = styled.span`...`;
... return <T><Strong>Please</Strong>don't</T>;

and what then?

simpler use cases

I often find myself writing stuff like <label htmlFor=...>{tUsername}</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.

0reactions
AlexMostcommented, Aug 2, 2019

@benmonro

The “oh no” doesn’t get put into the .PO file

That seems like a bug, will create a ticket for that.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found