i18next/i18next-xhr-backend

missing files prevent i18next from doing graceful language fallback

Pmagnard opened this issue · 4 comments

Hello,
i'm using i18next-xhr-backend in an HTML5 application (with jquery I18next plugin).
The application supports fr and en languages. When the detected language is fr-CA, i get errors such as

i18next::backendConnector: loading namespace common for language fr-CA failed failed loading /locales/fr-CA/common.json
and this prevents i18next to fallback to fr language.
When i'm testing the same configuration but without i18next-xhr-backend (defining my translation bundles directly in the javascript code), fallback from fr-CA to fr works fine.
I didn't find any option in i18next or xhr-backend to allow graceful fallback. Can you help please ?

i18next will load fr-CA, fr and the defined fallback language - please double check that fr does not get loaded

because fr-ca files are missing, the processing seems stopped.
In the i18next callback
i18next.init(i18nextOpts, function(err, t) {
err is set with the error "failed loading /locales/fr-CA/common.json".
I checked and fallback to fr does not happen.

Please console.log:

i18next.init(i18nextOpts, function(err, t) {
console.warn(i18next.services.resourceStore.data);
});

and paste your full i18next config (options)

I apologize, the fallback is not happening because of my code:

function(err, t) {
if (err) {
displayError(err);
} else {
//callback continues with translation work
If I remove the if/else, the processing is ok and fallback to fr occurs but i'm ignoring all errors coming from i18next. In my opinion, "failed loading /locales/fr-CA/common.json" should be treated as a warning, not an error but since the callback signature only provide an err element, i guess there is no way to distinguish between blocking and non-blocking errors. I'm consequently closing the issue. Thank you for your quick responses.