如何为 react-i18next `<Trans>` 组件设置语言?
How to set the language for the react-i18next `<Trans>` component?
使用 i18next 的基本翻译功能,您可以指定一种语言,以便并排显示英语和另一种语言:
import { useTranslation } from 'react-i18next'
...
const { t } = useTranslation()
...
`${t('Official Ballot')}/${t('Official Ballot', { lng: 'es' })}` // Official Ballot/Boleta Oficial
但是 <Trans>
组件似乎没有 lng
prop/option... 或者有吗?
(请忽略通常与 <Trans />
标签一起使用的附加 html 标记。这是一个简化的示例。)
import { Trans } from 'react-i18next'
...
<Trans i18nkey="Official Ballot" /> // Official Ballot
⬆如何为这个标签设置"lng"?
Trans
组件有一个 tOptions
道具,它被传递给 t
方法。
<Trans
i18nKey={"message"}
tOptions={{ lng: "de" }} // <--
components={[<strong>placeholder</strong>]}
/>
使用 i18next 的基本翻译功能,您可以指定一种语言,以便并排显示英语和另一种语言:
import { useTranslation } from 'react-i18next'
...
const { t } = useTranslation()
...
`${t('Official Ballot')}/${t('Official Ballot', { lng: 'es' })}` // Official Ballot/Boleta Oficial
但是 <Trans>
组件似乎没有 lng
prop/option... 或者有吗?
(请忽略通常与 <Trans />
标签一起使用的附加 html 标记。这是一个简化的示例。)
import { Trans } from 'react-i18next'
...
<Trans i18nkey="Official Ballot" /> // Official Ballot
⬆如何为这个标签设置"lng"?
Trans
组件有一个 tOptions
道具,它被传递给 t
方法。
<Trans
i18nKey={"message"}
tOptions={{ lng: "de" }} // <--
components={[<strong>placeholder</strong>]}
/>