Introduction

This is a simple i18next backend to be used in the browser. It will load resources from a backend server using the xhr API.
Getting started
Source can be loaded via npm, bower or downloaded from this repo.
# npm package
$ npm install i18next-xhr-backend
# bower
$ bower install i18next-xhr-backend
Wiring up:
import i18next from 'i18next';
import XHR from 'i18next-xhr-backend';
i18next.use(XHR).init(i18nextOptions);
- As with all modules you can either pass the constructor function (class) to the i18next.use or a concrete instance.
- If you don't use a module loader it will be added to
window.i18nextXHRBackend
Backend Options
{
loadPath: '/locales/{{lng}}/{{ns}}.json',
addPath: 'locales/add/{{lng}}/{{ns}}',
allowMultiLoading: false,
parse: function(data) { return data.replace(/a/g, ''); },
parsePayload: function(namespace, key, fallbackValue) { return { key } },
crossDomain: false,
withCredentials: false,
overrideMimeType: false,
customHeaders: {
authorization: 'foo',
},
ajax: function (url, options, callback, data) {},
queryStringParams: { v: '1.3.5' }
}
Options can be passed in:
preferred - by setting options.backend in i18next.init:
import i18next from 'i18next';
import XHR from 'i18next-xhr-backend';
i18next.use(XHR).init({
backend: options,
});
on construction:
import XHR from 'i18next-xhr-backend';
const xhr = new XHR(null, options);
via calling init:
import XHR from 'i18next-xhr-backend';
const xhr = new XHR();
xhr.init(null, options);
Misc
TypeScript definitions
-
Install from @types
(for TypeScript v2 and later):
npm install --save-dev @types/i18next-xhr-backend
-
Install from typings
:
typings install --save --global dt~i18next-xhr-backend