Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用参数翻译文本_Javascript_Reactjs_React Redux_Translation - Fatal编程技术网

Javascript 使用参数翻译文本

Javascript 使用参数翻译文本,javascript,reactjs,react-redux,translation,Javascript,Reactjs,React Redux,Translation,我正在制作一个多语言的react应用程序。我正在使用redux存储一个包含我所有翻译的对象 en.json { "loginMessage": "Welcome to my app", "loginButton": "Log in", "summary": "Viewing {p1} items totalling {p2}" } es.json { "loginMessage": "Bienvenido", "loginButton": "Iniciar sesion", "su

我正在制作一个多语言的react应用程序。我正在使用redux存储一个包含我所有翻译的对象

en.json

{
 "loginMessage": "Welcome to my app",
 "loginButton": "Log in",
 "summary": "Viewing {p1} items totalling {p2}"
}
es.json

{
 "loginMessage": "Bienvenido",
 "loginButton": "Iniciar sesion",
 "summary": "Viendo {p1} elementos totalizando {p2}"
}
我的应用程序中的一些文本是动态的,这意味着它包含数字或html标记。比如说

查看总计300.00美元的15个项目

所以我需要在字符串之间包含一些html标记。我提出了一个局部解决方案,它使用一个函数来替换我在中提供的变量的参数。使用这种方法,我必须提供html标记作为变量的一部分,如下所示

replaceAll(translation.summary, {
 "{p1}": `<strong> ${expenses.count} </strong>`,
 "{p2}": `<strong> ${expenses.total} </strong>`
})
replaceAll(translation.summary{
“{p1}”:`${expenses.count}`,
“{p2}”:“${expenses.total}`
})
我还需要将此函数放入一个名为危险的LysetinerHTML的react参数中,否则html标记将被视为字符串


这是完成工作,但我想知道是否有更好的方法。使用我不知道的功能。

您可以使用我以前使用的i18n react,这非常有用。
根据我的经验,最好有两个不同的url。你可以用谷歌翻译