【发布时间】:2021-08-31 05:15:24
【问题描述】:
我有一个 nextjs 应用程序,我想使用 i18next 和 next-i18next (https://github.com/isaachinman/next-i18next) 对其进行扩展。
默认配置是在./public/locales/{lng}/{ns}.json下寻找json文件,其中lng是语言,ns是命名空间。
然而,我的要求是,这应该从 api 端点提供。我正在努力寻找正确的配置,因为next-i18next 现在确实忽略了我的设置,并且没有向我的后端发起任何 xhr 请求。
next-i18next.config.js:
const HttpApi = require('i18next-http-backend')
module.exports = {
i18n: {
defaultLocale: 'de',
locales: ['en', 'de'],
},
backend: {
referenceLng: 'de',
loadPath: `https://localhost:5001/locales/de/common`,
parse: (data) => {
console.log(data)
return data
}
},
debug: true,
ns: ['common', 'footer', 'second-page'], // the namespaces needs to be listed here, to make sure they got preloaded
serializeConfig: false, // because of the custom use i18next plugin
use: [HttpApi],
}
我在这里不知所措。我做错了什么?
【问题讨论】:
-
这方面有进展吗?
-
是的,我已经解决了——只是没有来回答我自己的问题。今晚我会试一试
标签: reactjs next.js i18next react-i18next