只有几个类似的问题,这两个问题的解决方案在我的情况下都不起作用。这是给出此错误的代码片段:
homepage.tsx 文件:
export const CTASection = () => {
const {t, i18n} = useTranslation( {keyPrefix:("homepage.ctaSection")} )
return (
<StyledSection>
<CTAContainer>
<Header>{t('Header')}</Header>
<Subtitle>
Play and learn <i>risk-free</i>. Prove your knowledge, speculate and
win!
</Subtitle>
.....
我的 JSON 文件:
[
{
"homepage": {
"ctaSection": {
"header": "some thing"
}
}
}
]
我实际上正在尝试使用 JSON 文件的此内容显示在主页的标题部分中,而我实际上得到的是错误。
根据Doc,该选项位于第二个参数上。
const { t } = useTranslation('', { keyPrefix: 'homepage.ctaSection' });
尝试以下操作:
const { t } = useTranslation('homepage', { keyPrefix: 'ctaSection' });