【发布时间】:2018-07-13 17:32:54
【问题描述】:
我有以下代码试图在我想要翻译的反应项目中使用 i18next。
但是在调用应用程序时,我收到一个错误,即在 I18n 组件中出现 TypeError: Cannot read property 'options' of undefined。
// i18n components
import i18n from "/modules/ui/i18n";s
import { I18n } from 'react-i18next';
console.log(i18n);
export const renderRoutes = () => (
<I18n>
{
(t, { i18n }) => (
<Router history={browserHistory}>
<Switch>
<Route exact path="/" component={LandingPage} />
</Switch>
</Router>
)
}
</I18n>
);
我添加了 log 语句,它返回一个明确定义的 i18n 对象和 options 属性。不知道该怎么办。
我已将该属性移动到特定组件中,以防它与路由器功能不兼容并且发生相同的问题。
更新
问题出在 i18n 组件中。
i18n
.use(LanguageDetector)
.use(Backend)
.init({ ... })
改为
i18n
.use(LanguageDetector)
.use(Backend)
.use(reactI18nextModule)
.init({ ... })
问题解决了。
【问题讨论】:
-
你能改成这个(t, { i18n, t, ready })吗?
-
我最终面临这个问题。你能帮帮我吗
标签: reactjs i18next react-i18next