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

205
Visualizações
React i18n, how to interpolate to a string (i.e. without using <Trans> component)?

I have this function in my React component:

const fireError = (n) => {
   alert(`The value should go over ${n}% to be accepted.`);
}

in my translation JSON I have this:

{ "percentage": "The value should go over {{percentage}} to be accepted" }

How can I make this work? Of course I cannot use the Trans component.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use the i18n service directly:

// import it
import i18n from "i18next";

// in your React component
const fireError = (n) => {
   alert(i18n.t('percentage', { percentage: n }));
}

Keep in mind that the library has to be initialized before calling this function - i18n.init() must have already been invoked.

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