我有一条错误消息:
Cannot read property 'getFixedT' of undefined. TypeError: Cannot read property 'getFixedT' of undefined
at Translate.componentWillMount (webpack:///./~/react-i18next/dist/commonjs/translate.js?:78:46)
at eval (webpack:///./~/react-dom/lib/ReactCompositeComponent.js?:348:23)
at measureLifeCyclePerf (webpack:///./~/react-dom/lib/ReactCompositeComponent.js?:75:12)
at ReactCompositeComponentWrapper.performInitialMount (webpack:///./~/react-dom/lib/ReactCompositeComponent.js?:347:9)
at ReactCompositeComponentWrapper.mountComponent (webpack:///./~/react-dom/lib/ReactCompositeComponent.js?:258:21)
at Object.mountComponent (webpack:///./~/react-dom/lib/ReactReconciler.js?:46:35)
at ReactCompositeComponentWrapper.performInitialMount (webpack:///./~/react-dom/lib/ReactCompositeComponent.js?:371:34)
我的示例在组件中注册名称空间:
export default translate('example namespace', { wait: true })(MyComponent)
我的配置i18n.js看起来像:
import i18n from 'i18next';
import XHR from 'i18next-xhr-backend';
import LanguageDetector from 'i18next-browser-languagedetector';
export default i18n
.use(XHR)
.use(LanguageDetector)
.init({
fallbackLng: 'en',
ns: [
'example namespace',
],
defaultNS: 'example namespace',
debug: true,
backend: {
loadPath: 'locales/{{lng}}/{{ns}}.json',
},
});

我不知道如何解决这个问题,因为所有组件在浏览器中运行服务器时都使用语言资产。我使用kadira / storybook:" ^ 2.35.3",也许你有一些经验,如何设置故事书来加载我资产的所有命名空间。
答案 0 :(得分:1)
就我而言,我需要在故事书中添加addDecorator,并将我的故事包含在i18提供商中。