🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.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.

2.6.0
latest
Source
npm
Version published
Weekly downloads
803K
-13.1%
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

i18next

FAQs

Package last updated on 22 Nov 2024

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