【发布时间】:2019-01-09 04:08:45
【问题描述】:
以下代码在正常的 React 项目中工作(我使用的是打字稿,如果重要的话):
import {t} from "i18next";
const translation = t('WelcomeMessage');
同样的代码在 React Native 项目中不起作用,会报错:
import i18n, {t} from "i18next";
const translation1 = i18n.t('WelcomeMessage'); //works ok
const translation = t('WelcomeMessage'); //ERROR: (0, _i18next.t) is not a function
为什么t('WelcomeMessage') 在 RNative 中不起作用?是否与 i18next 在 typedefinitions (export = i18next;) 中的导出方式有关?
【问题讨论】:
-
react-i18next不是一个选项吗? -
我只是不需要它。我实际上可以在任何地方使用
i18n.t('SomeString'),我只是好奇为什么它不起作用 -
我的意思是,我很好奇为什么
t('WelcomeMessage')在 RNative 中不起作用 -
应该和metro bundler有关。
标签: reactjs typescript react-native i18next