Socket
Socket
Sign inDemoInstall

i18next-resources-to-backend

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i18next-resources-to-backend

This package helps to transform resources to an i18next backend


Version published
Weekly downloads
388K
increased by6.61%
Maintainers
1
Weekly downloads
 
Created

What is i18next-resources-to-backend?

The i18next-resources-to-backend npm package is a plugin for i18next that allows you to load translation resources from various backends. It simplifies the process of integrating different types of resource loading mechanisms into your i18next setup.

What are i18next-resources-to-backend's main functionalities?

Load translations from a custom backend

This feature allows you to define a custom backend for loading translations. The code sample demonstrates how to use a custom function to fetch translation files from a server.

const i18next = require('i18next');
const resourcesToBackend = require('i18next-resources-to-backend');

const customBackend = resourcesToBackend((language, namespace, callback) => {
  // Custom logic to fetch translations
  fetch(`/locales/${language}/${namespace}.json`)
    .then(response => response.json())
    .then(data => callback(null, data))
    .catch(error => callback(error, false));
});

i18next.use(customBackend).init({
  lng: 'en',
  fallbackLng: 'en',
  ns: ['translation'],
  defaultNS: 'translation'
});

Load translations from multiple backends

This feature allows you to combine multiple backends for loading translations. The code sample shows how to use both a custom backend and the i18next-http-backend together.

const i18next = require('i18next');
const resourcesToBackend = require('i18next-resources-to-backend');
const HttpBackend = require('i18next-http-backend');

const customBackend = resourcesToBackend((language, namespace, callback) => {
  // Custom logic to fetch translations
  fetch(`/locales/${language}/${namespace}.json`)
    .then(response => response.json())
    .then(data => callback(null, data))
    .catch(error => callback(error, false));
});

i18next.use(customBackend).use(HttpBackend).init({
  lng: 'en',
  fallbackLng: 'en',
  ns: ['translation'],
  defaultNS: 'translation'
});

Other packages similar to i18next-resources-to-backend

Keywords

FAQs

Package last updated on 19 May 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