Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

318
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda