admin管理员组文章数量:1426666
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.
本文标签:
版权声明:本文标题:javascript - React i18n, how to interpolate to a string (i.e. without using <Trans> component)? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745417914a2657770.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论