在React-I18Next中呼叫CDN?

发布于 2025-01-29 16:52:45 字数 895 浏览 3 评论 0原文

我正在尝试使用I18next-resources-backend和I18next-chared-backend使用此处推荐的框架来访问我本地化应用的资源: https://www.i18next.com/how-to/backend-fallback ,关键区别是我试图从CDN访问资源,而不是一个地方文件。

.init({
 fallbackLng: 'en',
 namespace: 'resources'
)}
backend: {
  backends: [
  HttpBackend,
  resourcesToBackend((language, namespace, callback) => {
  import(`./${language}/${namespace}.json`)
   .then(resources => {
    callback(null, resources)
})
.catch(error => {
callback(error, null)
})
 })
]
},
backendOptions: [
{
 loadPath: 'https://url/domain/link/dir/{language}}/{{namespace}}.json'
}
]

它无法正常工作,我在控制台中遇到此错误:

object {错误:错误}:错误:错误:无法找到模块'./es/translation.json'

有人有这个问题的经验吗?

I am attempting to access the resources for my localized app using i18next-resources-to-backend and i18next-chained-backend using the framework recommended here: https://www.i18next.com/how-to/backend-fallback, with the key difference being I am attempting to access the resources from a CDN, not a locale file.

.init({
 fallbackLng: 'en',
 namespace: 'resources'
)}
backend: {
  backends: [
  HttpBackend,
  resourcesToBackend((language, namespace, callback) => {
  import(`./${language}/${namespace}.json`)
   .then(resources => {
    callback(null, resources)
})
.catch(error => {
callback(error, null)
})
 })
]
},
backendOptions: [
{
 loadPath: 'https://url/domain/link/dir/{language}}/{{namespace}}.json'
}
]

It is not working and I am getting this error in the console:

Object { error: Error }: ​error: Error: Cannot find module './es/translation.json'

Anyone have experience with this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文