1.4.1 • Published 6 years ago

spa-gettext v1.4.1

Weekly downloads
5
License
MIT
Repository
github
Last release
6 years ago

STB SDK localization

build status npm version dependencies status devDependencies status Gitter

This localization module is an instance of Emitter module. Contains localization messages data used by other modules and provides methods to requests these messages.

Installation

npm install spa-gettext

Usage

Add to the scope:

var gettext = require('spa-gettext');

Load localization messages file (./lang/ru.json):

gettext.load({name: 'ru'}, function ( error ) {
    console.log(error);
});

Then it's possible to make direct calls to make simple replacement:

console.log(gettext('some line to be localized'));

Fetch a particular translation of the textual message:

console.log(pgettext('some context', 'some text'));

Native language translation of a textual message whose grammatical form depends on a number:

console.log(ngettext('{0} cat', '{0} cats', 1));

It's also possible to listen to instance events (load and error):

gettext.addListener('load', function () {
    // handle localization loading
});

gettext.addListener('error', function () {
    // handle localization loading
});

On localization loading for en language real AJAX request is not executed. There is loader.defaultLanguage option to control this behaviour.

Development mode

There is a global var DEVELOP which activates additional consistency checks and protection logic not available in release mode.

Contribution

If you have any problem or suggestion please open an issue here. Pull requests are welcomed with respect to the JavaScript Code Style.

License

spa-gettext is released under the MIT License.

1.4.1

6 years ago

1.4.0

8 years ago

1.3.0

8 years ago