Socket
Book a DemoInstallSign in
Socket

@autofleet/i18next-remote-backend-with-locals

Package Overview
Dependencies
Maintainers
11
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@autofleet/i18next-remote-backend-with-locals

An i18next backend plugin to work with both local resources and remote backend.

1.0.0
latest
Source
npmnpm
Version published
Weekly downloads
235
-41.54%
Maintainers
11
Weekly downloads
 
Created
Source

Introduction

An i18next backend plugin to work with both local resources and remote backend. This plugin supports any other i18next backend. This backend will first load the local resources, and then will override them with the remote version.

Getting started

Installation via NPM:

$ npm install i18next-remote-backend-with-locals

Setup:

import i18next from 'i18next';
import Backend from 'i18next-remote-backend-with-locals';

i18next
  .use(Backend)
  .init(i18nextOptions)

As with all modules you can either pass the constructor function (class) to the i18next.use or a concrete instance.

Backend Options

{
  // An object that contains i18next resources. For example:
  localResources: {
    en: {
      hello: "Hello"
    },
    ja: {
      hello: "こんにちは"
    }
  },

  // Any kind of supported backend. See example with i18next-http-backend:
  remoteBackend: {
    type: i18NextHttpBackend,

    // Any options that the backend type accepts
    options: {
      loadPath: "http://example.com",
      parse: data => data,
      request: (options, url, payload, callback) => {
        axios.get(url)
          .then(res => callback(null, res))
          .catch(err => callback(err, null));
      },
    }
  }
}

Options can passed in:

Preffered - by setting 'backend' property on i18next.init:

import i18next from 'i18next';
import Backend from 'i18next-remote-backend-with-locals';

i18next
  .use(Backend)
  .init({
    backend: options
  });

On construction:

import Backend from 'i18next-remote-backend-with-locals';

const Backend = new Backend(null, options);
const Backend = new Backend();
  Backend.init(null, options);

Via calling init:

import Backend from 'i18next-remote-backend-with-locals';

const Backend = new Backend();
Backend.init(null, options);

Complete Sample

import i18next from 'i18next';
import Backend from 'i18next-remote-backend-with-locals';
import i18NextHttpBackend from 'i18next-http-backend';
import en from './en.json';
import ja from './ja.json';
import id from './id.json';
import fr from './fr.json';

i18next
  .use(Backend)
  .init({
    fallbackLng: 'en',
    backend: {
      localResources: {
        en, 
        ja, 
        id, 
        fr,
      },
      remoteBackend: {
        type: i18nHttpLoader,
        options: {
          loadPath: 'http://example.com',
          parse: data => data,
          request: (options, url, payload, callback) => {
            axios.get(url)
              .then(res => callback(null, res))
              .catch(err => callback(err, null));
          },
        },
      },
    },
  });

Not supported

  • i18next Namespaces
  • Multiple backends

FAQs

Package last updated on 26 Oct 2020

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.