Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

i18next-chained-backend

Package Overview
Dependencies
Maintainers
2
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i18next-chained-backend

backend layer for i18next to chain backends

  • 4.6.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
163K
increased by3.26%
Maintainers
2
Weekly downloads
 
Created

What is i18next-chained-backend?

The i18next-chained-backend package is a backend layer for i18next that allows chaining multiple backends. This is useful for scenarios where you want to load translations from multiple sources, such as a local file system, a remote server, or a database, in a specific order.

What are i18next-chained-backend's main functionalities?

Chaining Multiple Backends

This feature allows you to chain multiple backends together. In this example, the translations are first attempted to be loaded from the local storage. If they are not found there, the HTTP backend is used as a fallback to load the translations from a remote server.

const i18next = require('i18next');
const ChainedBackend = require('i18next-chained-backend').default;
const HttpBackend = require('i18next-http-backend').default;
const LocalStorageBackend = require('i18next-localstorage-backend').default;

i18next.use(ChainedBackend).init({
  backend: {
    backends: [
      LocalStorageBackend, // primary
      HttpBackend // fallback
    ],
    backendOptions: [
      { /* options for local storage */ },
      { loadPath: '/locales/{{lng}}/{{ns}}.json' } // options for http backend
    ]
  }
});

Custom Backend Order

This feature allows you to define a custom order for the backends. In this example, a custom backend is used as the primary source, followed by local storage, and finally the HTTP backend as a fallback.

const i18next = require('i18next');
const ChainedBackend = require('i18next-chained-backend').default;
const HttpBackend = require('i18next-http-backend').default;
const LocalStorageBackend = require('i18next-localstorage-backend').default;
const CustomBackend = require('./myCustomBackend').default;

i18next.use(ChainedBackend).init({
  backend: {
    backends: [
      CustomBackend, // primary
      LocalStorageBackend, // secondary
      HttpBackend // fallback
    ],
    backendOptions: [
      { /* options for custom backend */ },
      { /* options for local storage */ },
      { loadPath: '/locales/{{lng}}/{{ns}}.json' } // options for http backend
    ]
  }
});

Other packages similar to i18next-chained-backend

Keywords

FAQs

Package last updated on 10 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc