【问题标题】:Pass Clickable dynamic value into react-i18next将 Clickable 动态值传递给 react-i18next
【发布时间】:2023-01-13 14:56:06
【问题描述】:
我正在动态传递值,但我想在单击此值时重定向到另一个页面。有没有办法做到这一点?
这是我的代码示例
// Page
t('product_create', {product_name: product_name, user_name: user_name} )
//Translation JSON File
"product_create": "{{product_name}} was created by {{user_name}}"
我想让产品名和用户名可以点击
【问题讨论】:
标签:
javascript
reactjs
i18next
react-i18next
【解决方案1】:
我解决了这个问题。
// JSX
<Trans i18nKey="product_create">
<Link to={`product/${product.id}`}>{product_name}</Link>
<Link to{`user/${user.id}`}>{user_name}</Link>
</Trans>
// JSON File
"product_create": "<1>{{product_name}}</1> Created By <1>{{user_name}}</1>"
来源:https://react.i18next.com/latest/trans-component