Internationalization i18next with HttpBackend,在初始化完成之前寻找密钥

Internationalization i18next with HttpBackend,在初始化完成之前寻找密钥,internationalization,i18next,react-i18next,i18next-http-backend,Internationalization,I18next,React I18next,I18next Http Backend,我使用HttpBackend动态加载翻译 然而,在我的组件中,我使用了Trans组件,它正在尖叫着缺少翻译键,我还看到init在尝试访问Trans组件后完成了。 我的应用程序有一个悬念,为什么会发生这种情况 我进入控制台: i18next::translator:missingKey en translation myKey这是一个包含的文本 初始化发生在之后 我怎样才能解决这个问题 //文件:i18n.js i18n //使用http->see/public/locales加载翻译(即。htt

我使用HttpBackend动态加载翻译 然而,在我的组件中,我使用了Trans组件,它正在尖叫着缺少翻译键,我还看到init在尝试访问Trans组件后完成了。 我的应用程序有一个悬念,为什么会发生这种情况

我进入控制台: i18next::translator:missingKey en translation myKey这是一个包含
的文本 初始化发生在之后

我怎样才能解决这个问题

//文件:i18n.js
i18n
//使用http->see/public/locales加载翻译(即。https://github.com/i18next/react-i18next/tree/master/example/react/public/locales)
//了解更多信息:https://github.com/i18next/i18next-http-backend
.使用(后端)
//检测用户语言
//了解更多信息:https://github.com/i18next/i18next-browser-languageDetector
//将i18n实例传递给react-i18next。
.使用(initReactI18next)
//init i18next
//对于所有选项,请阅读:https://www.i18next.com/overview/configuration-options
.init({
撤退:“恩”,
是的,
支持的语言:['en','bg','rs'],
插值:{
escapeValue:false,//对于react不需要,因为默认情况下它会转义
},
后端:{
加载路径:'/static/{{lng}}.translations.json',
},
反应:{
等等:是的,
悬念:是的,
},
transSupportBasicHtmlNodes:true,
});
导出默认i18n;
//app.js
函数App(){
返回(
);
}
有问题的组件:

//主页
常量I18N_TEXT_KEY_常量='TEXT_KEY';
常量Home=()=>(
这是一个包含
和一些随机空格的文本。 );
令人遗憾的是,本文档中没有提到的解决方案是:

const {t}  = useTranstions()
<Trans i18nKey="someKey" t={t}>
const{t}=usetransions()

将t传递到Trans中工作正常。

您应该将
t
功能传递到
Trans
组件

//主页
从“react-i18next”导入{useTranslation};
常量I18N_TEXT_KEY_常量='TEXT_KEY';
常量Home=()=>{
const{t}=useTranslation();
返回(
这是一个包含
和一些随机空格的文本。 ); };
试着从你的UseTransformation钩子中传递t道具是的,我想了那么多,昨天晚上就成功了..这太傻了,没有记录在案!