小编ehr*_*ona的帖子

i18n 错误(错误:您正在传递未定义的模块!请检查您传递给 i18next.use() 的对象)

我正在尝试在我的 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
Run Code Online (Sandbox Code Playgroud)

然后我设置了 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
Run Code Online (Sandbox Code Playgroud)

将其导入到我的布局组件中:

import React …
Run Code Online (Sandbox Code Playgroud)

gatsby react-i18next

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

gatsby ×1

react-i18next ×1