react-i18next 忽略选项参数

react-i18next ignores options parameter

我想更好地组织我的项目的语言翻译文件,不得不在语言文件中嵌套对象。

我已经尝试打印 useTranslation 实例以查看它是否正在接收“keyPrefix”值,但它总是在 t 或 fixedT 函数上显示 'undefined'。

lang文件是这样的:

export const en = {
  section:{
    subsection:{
      text:'my text',
    }
  }
}

我使用 useTranslation 挂钩的文件:

const { t } = useTranslation('section', { keyPrefix: 'subsection' });

<h1>{t('text')}</h1>

这取自文档

// having resources like this:
/*{
  "translation": {
    "very": {
      "deeply": {
        "nested": {
          "key": "here"
        }
      }
    }
  }
}*/
// you can define a keyPrefix to be used for the resulting t function
const { t } = useTranslation('translation', { keyPrefix: 'very.deeply.nested' });
const text = t('key'); // "here"

我有一个旧的 node.js 版本。

更新它(nvm 是一个很好的工具)然后瞧瞧

当我遇到这个问题时,我已将 Node.js 从 12.14.0 更新到 14.19.0。