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

i18next-fs-backend

Package Overview
Dependencies
Maintainers
2
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i18next-fs-backend

i18next-fs-backend is a backend layer for i18next using in Node.js and for Deno to load translations from the filesystem.

  • 1.1.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
865K
decreased by-3.01%
Maintainers
2
Weekly downloads
 
Created

What is i18next-fs-backend?

The i18next-fs-backend package is a file system backend for i18next, a popular internationalization framework for JavaScript. This backend allows you to load translation files from the file system, making it suitable for server-side applications like Node.js.

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

Loading translations from the file system

This feature allows you to load translation files from a specified path on the file system. The 'loadPath' option specifies the path pattern where the translation files are located.

const i18next = require('i18next');
const Backend = require('i18next-fs-backend');

i18next.use(Backend).init({
  backend: {
    loadPath: '/locales/{{lng}}/{{ns}}.json'
  },
  lng: 'en',
  fallbackLng: 'en',
  ns: ['translation'],
  defaultNS: 'translation'
}, (err, t) => {
  if (err) return console.error(err);
  console.log(t('key')); // prints the translation for 'key'
});

Custom file system operations

This feature allows you to customize how the backend reads and writes files. You can provide your own 'readFile' and 'writeFile' functions to handle file operations.

const i18next = require('i18next');
const Backend = require('i18next-fs-backend');
const fs = require('fs');

i18next.use(Backend).init({
  backend: {
    loadPath: '/locales/{{lng}}/{{ns}}.json',
    addPath: '/locales/{{lng}}/{{ns}}.missing.json',
    readFile: (file, cb) => {
      fs.readFile(file, 'utf8', cb);
    },
    writeFile: (file, data, cb) => {
      fs.writeFile(file, data, 'utf8', cb);
    }
  },
  lng: 'en',
  fallbackLng: 'en',
  ns: ['translation'],
  defaultNS: 'translation'
}, (err, t) => {
  if (err) return console.error(err);
  console.log(t('key')); // prints the translation for 'key'
});

Other packages similar to i18next-fs-backend

Keywords

FAQs

Package last updated on 13 Nov 2021

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