我试图在我的React应用程序中使用i18next与插值
以下是React代码中的示例
{i18n.t('hours', {ns:'namespace', count: 100})}
<Trans i18nKey='hours' ns='namespace' count={10}/>
{t('hours', {count: 1})}
这是我的' namspace .json'
"hours_one": "час",
"hours_few": "часа",
"hours_many": "часов"
"hours": "часы {{count}}"
这是我的输出
часы 100
часы {{count}}
часы 1
如你所见,不起作用。我不知道为什么。有人能告诉我我做错了什么吗?
设置const resources = {
ru: {
namespace: namespaceRU
}
};
i18n
.use(Backend)
.use(LanguageDetector)
.use(initReactI18next)
.init({
resources,
fallbackLng: 'ru',
debug: true,
supportedLngs: ['ru'],
interpolation: {
escapeValue: false, // not needed for react as it escapes by default
},
react: {
useSuspense: false
},
});
您需要更改Trans
组件中的2个内容:
- 通过
t
Trans
- 使用
values
prop来通过count
<Trans t={t} i18nKey='hours' ns='namespace' values={{count: 10}}/>