i18下一个后端连接器:加载语言 fr 的命名空间翻译失败



我想从我们的翻译微服务中获取翻译,所以我正在使用i18next-http-backend库。

到目前为止,我只是想测试我需要将哪种对象传递给请求参数中的回调,但我不断出现错误:i18next::backendConnector: loading namespace translations for language fr failed', { test: 'Blah' }

目前我的代码如下。有谁知道它为什么失败?

import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import Backend from 'i18next-http-backend';
i18n.use(Backend)
.use(initReactI18next)
.init({
backend: {
crossDomain: false,
withCredentials: false,
overrideMimeType: false,
requestOptions: {
// used for fetch, can also be a function (payload) => ({ method: 'GET' })
mode: 'cors',
credentials: 'same-origin',
cache: 'default'
},
request: function(
options,
url,
callback,
payload
) {
callback(
{ test: 'Blah' },
{
status: 200
}
);
},
reloadInterval: false
},
lng: 'fr',
fallbackLng: false,
debug: true,
ns: ['translations'],
defaultNS: 'translations',
react: {
useSuspense: false,
wait: true
},
interpolation: {
escapeValue: false
}
});
export default i18n;

从文档中:

">

回调"是一个接受两个参数的函数,"err"和"res"。 "错误"应该是一个错误 "res"应该是具有"状态"属性和"数据"属性的对象 包含字符串化对象实例,该实例支持键:值 所请求语言的翻译对,以及 命名空间,或在出现错误时为 null。

您缺少第一个参数("err"(:

callback(null, {...});

尝试声明一个 defaultNS:

ns: ['common'],
defaultNS: 'common'

最新更新