jm-ez-l10n
Easy Localization for NodeJS
Installation
npm install jm-ez-l10n --save
Configure
Load language files, in your main server.js/index.js file,
var l10n = ; // Set Translations by json filel10n;l10n; // Or else by pure js objectl10n; l10n; // Variables and add translation to existingl10n;
End User APIs
Localization is only needed when you want to localize content based on User's locale.
If you are using core NodeJS, Enable l10n to any damm object!! by just a line...
// Enable l10nvar any = {};l10n // Usageconsole; // 10 items found!console; // Displaying 10 of 25 records
If you are using Express framework, which is worldwide accepted! use below middleware,
// Express Middleware works beautifully here...var express = ;var app = ; // Using custom header X-L10N-Localeapp;app;
Example:
// cURL - en// curl -X POST -H "X-L10N-Locale: en" -H "Content-Type: application/json" -d '{"abc":"123"}' http://localhost:1338/anyReq app; // cURL - fr// curl -X POST -H "X-L10N-Locale: fr" -H "Content-Type: application/json" -d '{"abc":"123"}' http://localhost:1338/anyReq app;
CLI Usage
If you are using from CLI, no user locale will be there right, so you may use it's global version,
// This will set locale globally on serverl10n;console; // Hello! l10n;console; // salut!
License
The MIT License (MIT)