[英]i18next load json from api using i18next-xhr-backend
我尝试从 React Native 中的 API 加载翻译 JSON 文件并解析它,但似乎加载不起作用,因为解析方法从不调用。
function initI18Next(onInit) {
return (
i18n
.use(initReactI18next)
.use(XHR)
.init({
...initOptions,
backend : backendOptions
}).then(onInit())
)}
初始化选项:
export const initOptions = {
fallbackLng : 'es',
defaultNS : 'translation',
lng : 'es',
debug: true,
keySeparator : false,
initImmediate: false,
preload : ['en', 'es'],
react: {
wait: true,
useSuspense: false
},
interpolation: {
escapeValue: true // not needed for react as it escapes by default
},
resources : i18nResources
}
后端选项:
export const backendOptions = {
loadPath: 'http://www.mocky.io/v2/5ecd0fe73200006400236655.json',
parse(data) {
console.log('data', data);
return data;
}
};
i18next-xhr-backend 已弃用,请改用 i18next-http-backend... 然后尝试将 i18next 调试选项设置为 true 并查看开发人员控制台日志。
顺便说一句:加载路径对我来说看起来很奇怪。 它应该更像这样:https://github.com/i18next/i18next-http-backend#backend-options
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.