作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在我的 Gatsby 项目中设置 i18n。
我一直在一步一步地学习本教程:
https://www.gatsbyjs.org/blog/2017-10-17-building-i18n-with-gatsby/
首先我下载所需的包:
npm i -S i18next i18next-xhr-backend i18next-browser-languagedetector react-i18next
然后我设置了 i18n 组件
import i18n from "i18next"
import Backend from "i18next-xhr-backend"
import LanguageDetector from "i18next-browser-languagedetector"
import { reactI18nextModule } from "react-i18next"
i18n
.use(Backend)
.use(LanguageDetector)
.use(reactI18nextModule)
.init({
fallbackLng: "en",
// have a common namespace used around the full app
ns: ["translations"],
defaultNS: "translations",
debug: true,
interpolation: {
escapeValue: false, // not needed for react!!
},
react: {
wait: true,
},
})
export default i18n
在我的布局组件中导入它:
import React from "react"
import "./layout.scss"
import NavMenu from "./NavMenu/navMenu"
import i18n from './i18n/i18n'
export default function Layout({ children }) {
return (
<div className="container">
<NavMenu />
{children}
</div>
)
}
但是,当我运行我的应用程序时,出现以下错误:
最佳答案
进口自 react-i18next
是错的。它应该是import { initReactI18next } from "react-i18next"
和.use(initReactI18next)
如果您尝试导入未导出的内容,则该值未定义,然后 use
给你你看到的消息。
好像叫reactI18nextModule
在 react-i18next
的早期版本中这就是为什么你可以找到使用它的教程。
我做了一个 demonstration of the exports in RunKit
关于gatsby - i18n 错误(错误 : You are passing an undefined module! 请检查您传递给 i18next.use() 的对象),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62849265/
我是一名优秀的程序员,十分优秀!