1

我有以下代码试图在我要翻译的反应项目中使用 i18next。

但是在调用应用程序时,我收到一个错误,即 I18n 组件 aTypeError: 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>
);

i18n我已经添加了日志语句,它返回了一个带有options属性的明确定义的对象。不知道该怎么办。

我已将该属性移动到特定组件中,以防它与路由器功能不兼容并且发生了同样的问题。

更新

问题出在 i18n 组件中。

i18n
  .use(LanguageDetector)
  .use(Backend)
  .init({ ... })

改为

i18n
  .use(LanguageDetector)
  .use(Backend)
  .use(reactI18nextModule)
  .init({ ... })

问题就解决了。

4

1 回答 1

1

我在缺少该.use(reactI18NextModule)部分的更新中添加了答案。

于 2018-07-13T21:44:32.083 回答