I have this function in my React ponent:
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 ponent.
I have this function in my React ponent:
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 ponent.
Share Improve this question asked Sep 20, 2021 at 16:52 nicknick 3,2876 gold badges43 silver badges85 bronze badges 1-
use
t('percentage')
, as for how to setup reacti18n
, check documentation – windmaomao Commented Sep 20, 2021 at 16:57
1 Answer
Reset to default 4You can use the i18n
service directly:
// import it
import i18n from "i18next";
// in your React ponent
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.