stb-gettext
v1.3.0
Published
STB SDK localization.
Downloads
6
Maintainers
Readme
STB SDK localization
STB SDK localization module. It's an instance of Model component. Contains localization messages data used by other modules and provides methods to requests these messages.
Installation
npm install stb-gettext
Usage
Add to the scope:
var gettext = require('stb-gettext');
Load localization messages file (./lang/ru.json
):
gettext.load({name: 'ru'}, function ( error, data ) {
debug.log(error);
debug.inspect(data);
});
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
):
// subscribe to events
gettext.addListener('load', function () {
...
});
Debug mode
There is a global var
DEBUG
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
stb-gettext
is released under the GPL-3.0 License.