Skip to content

How to use Trans Macro or "t" tag within a map function? Also how to preserve line break styling? #1491

Answered by thekip
crazyyi asked this question in Q&A
Discussion options

You must be logged in to vote

Translating from variables is not going to work

// Wrong!
<>
  <div><Trans>{v}</Trans></div>
  <div><Trans>{answers[i]}</Trans></div>
</>

Extractor, not executing your code, it only analyzing it during compilation. So all messages should be marked for translation in place where they are defined. Extractor has no idea what is {v} or {answers[i]} when it analyzes <Trans> macro.

both of the questions and answers are strings or ReactNodes.

Normalize them to only react nodes (or if it's possible to only strings):

const FAQs = [
  {
    q: <Trans>question1</Trans>,
    a: <Trans>ans1</Trans>,
  },
  {
    q: <Trans>question2</Trans>,
    a: <>
      <div><Link><Trans>Click me</Trans></Link></div

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by crazyyi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants