browser-i18n
A simple in-browser i18n module, compatible with the i18n-node server module data files. Meant to be use with a module bundler (like parcel).
Installation
By using npm:
npm i browser-i18n --save
Usage
; const i18n = language: 'fr' path: '/locales' extension: '.json'; console;// Output: 'Bonjour' console;// Output: 'Oh, salut Mark!' // Or using the global selector ... console;// Output: 'Bonjour'
Files structures
One file for each language. They may have the following structure:
// /locales/en.json
// /locales/fr.json
Put your locales folder accessible publicly. You can do it by putting it in your public root:
.
└── public
└── locales
├── en.json
└── fr.json
Or, using express:
app;
API
Configuration:
const i18n = language: 'fr' // The langage wanted - Default 'en' path: '/locales' // The path to access the locales files - Default '/locales' extension: '.json' // Local file extension - Default '.json' setGobal: true // Set the function '__' on a global scope - Default true onReady: callback // Set a callback triggered when the dataFile is loaded verbose: true // Set the verbosity of the object - Default to true;