Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

320
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda