Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

317
Views
How to put html code inside react18next json translation file?

I have blog page on multiple languages and I use react-i18next library for translation. I have one component called BlogPostPage where I show each post when it's opened, inside the component there is part for showing blog text like this:

    import { useTranslation } from "react-i18next";
      const [t] = useTranslation(["translation1", "overview"]);
          ..........
        <Typography mb={2} component="p" variant="subtitle1">
            {t(`text${state.id}1`)}
        </Typography>

and my json translation file looks like this

{
"text51":"<h4>Welcome to our application</h4>",
}

So I want to put html code inside translation text since different post has different html code it really needs to be in json file and not in the component... is there any way that can be done?

Output of my code is:

<h4>Welcome to our application</h4>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Your issue is that react will try to escape any html it find in strings like this. If you absolutely need to do this you can use the following method:

<div dangerouslySetInnerHTML={{__html: t(`text${state.id}1`)}} />

Beware that there is a reason that react calls this prop dangerouslySetInnerHTML, and doing this is very much an anti-pattern.

about 4 years ago · Juan Pablo Isaza Report

0

Use the Trans component: https://react.i18next.com/latest/trans-component

<Trans i18nKey="text51">
  <h4>Welcome to our application</h4>
</Trans>

With <0> instead of <h4>

"text51": "<0>Welcome to our application</0>"
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!