Tengo esta función en mi componente React:
const fireError = (n) => { alert(`The value should go over ${n}% to be accepted.`); }en mi traducción JSON tengo esto:
{ "percentage": "The value should go over {{percentage}} to be accepted" }¿Cómo puedo hacer que esto funcione? Por supuesto que no puedo usar el componente Trans.
Puede utilizar el servicio i18n directamente:
// import it import i18n from "i18next"; // in your React component const fireError = (n) => { alert(i18n.t('percentage', { percentage: n })); } Tenga en cuenta que la biblioteca debe inicializarse antes de llamar a esta función: ya se debe haber invocado i18n.init() .