开发者社区> 镜像站> NPM> i18next-callback-backend
i18next-callback-backend
A "custom callback" backend for i18next.
Last updated 5 years ago by mathieumg .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install i18next-callback-backend 
SYNC missed versions from official npm registry.

CustomCallbackBackend for i18next

This is a very simple i18next backend to be used in the browser or in the server. It allows you to tap in to i18next's callback to load resources without having to write the boilerplate yourself.

Getting 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 */,
});

Current Tags

  • 1.0.0-alpha.1                                ...           latest (5 years ago)

1 Versions

  • 1.0.0-alpha.1                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (18)
Dependents (1)