我尝试使用https://react.i18next.com/进行本地化,我得到了错误:试图导入错误:'initReactI18next‘不是从’Reacti-i18Next‘导出的。
这是我的i18n.js文件:
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import Backend from 'i18next-http-backend';
import LanguageDetector from 'i18next-browser-languagedetector';
// not like to use this?
// have a look at the Quick start guide
// for passing in lng and translations on init
i18n
// load translation using http -> see /public/locales (i.e. https://github.com/i18next/react-i18next/tree/master/example/react/public/locales)
// learn more: https://github.com/i18next/i18next-http-backend
.use(Backend)
// detect user language
// learn more: https://github.com/i18next/i18next-browser-languageDetector
.use(LanguageDetector)
// pass the i18n instance to react-i18next.
.use(initReactI18next)
// init i18next
// for all options read: https://www.i18next.com/overview/configuration-options
.init({
fallbackLng: 'en',
debug: true,
interpolation: {
escapeValue: false, // not needed for react as it escapes by default
}
});
export default i18n;我的package.json
{“名称”:"heatmann",“版本”:"0.1.0",“私有”:true,
“依赖项”:{ "axios":"^0.19.0","i18next":"^19.4.5",“i18Next-浏览器-语言检测器”:"^4.3.0",“i18Next-http-后端”:"^1.0.15",“i18Next-xhr-后端”:"^3.2.2",“支柱-类型”:"^15.7.2",“丙型”:"^1.1.0“、”反应“:"^16.12.0”、“反应-爱丽丝-旋转木马”:"^1.17.2“、”反应-多姆“:"^16.12.0”、“反应-i18Next”:"^9.0.10“、”反应-装载机-旋转器“:"^3.1.5",反应-本机-手势-处理程序:"^1.5.2",“反应-导航”:"^4.0.10",“反应-导航-堆栈”:"^1.10.3",“反应-路由器-多姆”:"^5.1.2",“反应-脚本”:"^3.3.0“},”脚本“:{”开始“:”反应-脚本启动“,“构建”:“反应-脚本构建”,“测试”:“反应-脚本测试”,“弹出”:“反应-脚本弹出”},"eslintConfig":{“扩展”:"react-app“},”浏览列表“:{”产品“:">0.2%",”不死“,”不全部“,“开发”:“最后一个铬版”、“最后一个火狐版本”、“最后一个safari版本”}、"devDependencies":{“@babel/plugin-提案-导出-默认-从”:"^7.8.3",“css-加载程序”:"^3.4.2“} }
发布于 2020-06-18 06:32:12
删除带有package.json的i18next条目。
删除所有node_modules文件夹
重新安装npm install
npm install react-i18next i18next --save //当希望检测用户语言和加载转换时
npm install i18next-http-backend i18next-browser-languagedetector --save
这解决了我的问题。
发布于 2020-11-23 15:28:02
npm install react-i18next i18next --save或
yarn add react-i18next i18next https://stackoverflow.com/questions/62429986
复制相似问题