i18next load json from api using i18next-xhr-backend

Viewed 1672

I try to load a translation JSON file from API in React Native and parse it but it seems that load does not work because the parse method never invokes.

function initI18Next(onInit) {

return (
    i18n
        .use(initReactI18next)
        .use(XHR)
        .init({
            ...initOptions,
            backend : backendOptions
        }).then(onInit())
)}

initOptions :

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

}

backend options :

export const backendOptions = {
loadPath: 'http://www.mocky.io/v2/5ecd0fe73200006400236655.json',
parse(data) {
    console.log('data', data);

    return data;
}

};

1 Answers
Related