CustomCallbackBackend
for i18nextGetting started
Package can be downloaded via npm.npm install i18next-callback-backend
Wiring up:
import i18next from "i18next";
import CustomCallbackBackend from "i18next-callback-backend";
i18next
.use(CustomCallbackBackend)
.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.i18nextCustomCallbackBackend
Backend Options
{
// Callback used when loading a single resource.
customLoad: (language, namespace, callback) => {
// Your custom loading logic.
callback(null, /* your loaded resource */);
},
// Callback used when loading multiple resources. (Optional)
customLoadMulti: (languages, namespaces, callback) => {
// Your custom loading logic.
callback(null, /* your loaded resources */);
},
// Callback used when saving resources. (Optional)
customCreate: (languages, namespace, key, fallbackValue) => {
// Your custom saving logic.
},
}
Options can be passed in:
preferred - by setting
options.customLoad
, in i18next.init:import i18next from "i18next";
import CustomCallbackBackend from "i18next-callback-backend";
i18next
.use(CustomCallbackBackend)
.init({
customLoad: /* your custom callback */,
customLoadMulti: /* your custom callback */,
customCreate: /* your custom callback */,
});
on construction:
import CustomCallbackBackend from "i18next-callback-backend";
const customCallbackBackend = new CustomCallbackBackend(
null,
{
customLoad: /* your custom callback */,
customLoadMulti: /* your custom callback */,
customCreate: /* your custom callback */,
}
);
via calling init:
import CustomCallbackBackend from "i18next-callback-backend";
const customCallbackBackend = new CustomCallbackBackend();
customCallbackBackend.init({
customLoad: /* your custom callback */,
customLoadMulti: /* your custom callback */,
customCreate: /* your custom callback */,
});