i18n翻译使变量变为粗体



我试图在中生成一个位于中转换字符串中间的变量,但找不到解决方案。我需要两种不同语言的所有翻译:"en"one_answers"de">

我的代码如下:

import { useTranslation } from 'react-i18next'

const { t } = useTranslation('payment');

const companyName = 'Probando'

<Typography>{ t('setup with company name', <b>{companyName: companyName}</b>)</Typography>

我的翻译文件:

支付en.json{ "setup with company name": "Please contact {{ companyName }} to re-edit or re-send this invitation.", }

付款方式:{ "setup with company name": "Bitte wenden Sie sich an {{ companyName }} um diese Einladung nochmal zu bearbeiten oder neu zu erhalten." }

如果要在翻译中使用标记,则需要使用Trans组件。

https://react.i18next.com/latest/trans-component

import { Trans } from 'react-i18next'
const { t } = useTranslation('payment');
<Trans t={t} i18nKey="setup with company name">
Please contact <b>{{ companyName }}</b> to re-edit or re-send this invitation.
</Trans>

然后是这样的翻译:

// EN
"setup with company name": "Please contact <1>{{companyName}}</1> to re-edit or re-send this invitation.",
// DE
"setup with company name": "Bitte wenden Sie sich an <1>{{ companyName }}</1> um diese Einladung nochmal zu bearbeiten oder neu zu erhalten."

最新更新