i18next 复数使用计数返回一个对象而不是字符串
i18next plurals using count returned an object instead of string
试图用 i18next-react
找出复数。我一定错过了一些非常明显的东西。我收到错误 Results in key 'generic.rule-group (en)' returned an object instead of string.
提前致谢
resources.json
{
"en": {
"default": {
"generic.rule-group": {
"one": "Rule group",
"other": "Rule groups"
}
}
}
}
jsx
import React from 'react';
import { useTranslation } from 'react-i18next';
export const Test = () => {
const { t } = useTranslation()
// Results in key 'generic.rule-group (en)' returned an object instead of string.
return <h1>{t('generic.rule-group', { count: 1 })}</h1>
}
i18next-config.js
i18next
.use(initReactI18next)
.init({
ns,
fallbackNS: 'default',
defaultNS: ns,
lng: 'en',
fallbackLng: 'en',
resources,
keySeparator: false,
interpolation: {
escapeValue: false,
},
})
.catch(error => {
console.log(error);
});
According to the documentation,我觉得资源json键应该是:
{
"en": {
"default": {
"generic.rule-group": "Rule group",
"generic.rule-group_plural": "Rule groups"
}
}
}
}
试图用 i18next-react
找出复数。我一定错过了一些非常明显的东西。我收到错误 Results in key 'generic.rule-group (en)' returned an object instead of string.
提前致谢
resources.json
{
"en": {
"default": {
"generic.rule-group": {
"one": "Rule group",
"other": "Rule groups"
}
}
}
}
jsx
import React from 'react';
import { useTranslation } from 'react-i18next';
export const Test = () => {
const { t } = useTranslation()
// Results in key 'generic.rule-group (en)' returned an object instead of string.
return <h1>{t('generic.rule-group', { count: 1 })}</h1>
}
i18next-config.js
i18next
.use(initReactI18next)
.init({
ns,
fallbackNS: 'default',
defaultNS: ns,
lng: 'en',
fallbackLng: 'en',
resources,
keySeparator: false,
interpolation: {
escapeValue: false,
},
})
.catch(error => {
console.log(error);
});
According to the documentation,我觉得资源json键应该是:
{
"en": {
"default": {
"generic.rule-group": "Rule group",
"generic.rule-group_plural": "Rule groups"
}
}
}
}