我正在尝试在我的 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)