1.1.0 • Published 6 years ago

nodejs-locale v1.1.0

Weekly downloads
10
License
ISC
Repository
github
Last release
6 years ago

Localization for NodeJS

A simple yet powerful module that loads a locale from a JSON file. This is a perfect if you looking to make your nodejs project multilingual.

Usage

const T = require('nodejs-locale');

var t = new T({
    locale: 'en', // The locale directory to look into
    module: ['users'], // The locale file(s) to load
    dir: './locales', // The path where all the locale folders for eg. 'en' are placed.
    silentFail: true // Do not throw an exception if a module is not found
});

// With the above settings, this module will look for a locale file at: ./locales/en/users.json

// Outputs a simple string
console.log(t._('simple'));
console.log(t._('greetings'));


// Can also be used for nested JSON
console.log(t._('simple').a.b);

// Outputs a formatted string
console.log(t._('advanced', ['soubhik', 'angular']));

// Change the locale at run-time
t.locale = 'fr'

// Add a module name at run-time
t.addModule('users');

// Remove a module
t.removeModule('users');

// Get all modules
console.log(t.modules);

// Get locale string
console.log(t._('greetings'));

Checkout the Example

Options

Option NameDescriptionData TypeOptionalDefault Value
localeThe local folder nameStringNo-
moduleThe module to loadStringNo-
dirCustom directory from where the locale should be loaded.StringYes./resources/locale
silentFailDoes not throw an exception if a module path is not foundBooleanYesfalse
1.1.0

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago