react-i18next并用组件替换占位符键

问题描述 投票:0回答:1

以前我使用react-intl并且能够为可以用组件替换的项目设置占位符,例如{br}<br />

我正在尝试使用react-i18nexti18next-icu时遇到错误:

// Using Intl format (via i18next-icu)
{
  "test": "Replace with a{br}line-break. {button}"
}
t("test", { br: <br />, button: <button>Click me!</button> });
// Outputted translated text
Replace with a[object Object]line-break. [object Object]

实际上是否可以使用i18next / i18next-icu来做到这一点?如果没有,那么将组件插入到翻译的字符串中的另一种方法是什么?

reactjs i18next react-intl react-i18next
1个回答
0
投票

https://react.i18next.com/latest/trans-component会在您的翻译中包含反应成分(如br,strong,...)

© www.soinside.com 2019 - 2024. All rights reserved.