i18next / i18next-http-backend

i18next-http-backend is a backend layer for i18next using in Node.js, in the browser and for Deno.
MIT License
454 stars 71 forks source link

Translations not loaded after migrating from i18next-xhr-backend #16

Closed jbanulso closed 4 years ago

jbanulso commented 4 years ago

🐛 Bug Report

Attempting to upgrade from the deprecated i18n-xhr-backend to i18next-http-backend with the same configuration approach means the translations keys are no longer loaded. They are downloaded from the server successfully, but it seems that the json response is not parsed by i18next-http-backend.

To Reproduce

Moving from this config in i18n-xhr-backend:

ajax: async (url, options, callback) => {
  try {
    const response = await customFetch(url);
    const body = await response.text();
    callback(body, response);
  } catch (e) {
    console.info('Error fetching translations', e);
    callback(null, e);
  }
}

to this one in i18n-http-backend:

request: async (options, url, payload, callback) => {
  try {
    const response = await customFetch(url);
    const body = await response.text();
    callback(body, response);
  } catch (e) {
    console.info('Error fetching translations', e);
    callback(null, e);
  }
}

breaks the translations, and results in a bunch of "missing keys" debug messages in the console.

(customFetch is just adding a number of headers and tokens to the fetch request)

Expected behavior

The translations should be displayed in my application.

Your Environment

adrai commented 4 years ago

The callback signature is different... example: https://github.com/i18next/i18next-http-backend/blob/master/lib/index.js#L65

jbanulso commented 4 years ago

@adrai Ah I see, my bad. Thank you for the quick response, and for changing the Readme.