1.0.5 • Published 7 years ago
cjs-gettext v1.0.5
STB SDK localization
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 cjs-gettextUsage
Example data format:
{
"meta": {
"charset": "utf-8",
"project": "downloads",
"language": "ru",
"plural": "(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)"
},
"data": {
"": {
"some text": "некоторый текст",
"Close": "Закрыть",
"Error": "Ошибка",
"File name:": "Имя файла:",
},
"some context": {
"some text": "Лирика",
"Close": "Выйти",
"Error": "Недопустимое действие",
}
}
}Add the constructor to the scope and create an instance with some data:
var Gettext = require('cjs-gettext'),
gettext = new Gettext(data);Then it's possible to make direct calls to make simple replacement:
console.log(gettext.gettext('Close'));Fetch a particular translation of the textual message:
console.log(gettext.pgettext('some context', 'some text'));Native language translation of a textual message whose grammatical form depends on a number:
console.log(gettext.ngettext('{0} cat', '{0} cats', 1));Development mode
There is a global var
DEVELOPwhich activates additional consistency checks and protection logic not available in release mode.
Contribution
If you have any problems or suggestions please open an issue according to the contribution rules.
License
cjs-gettext is released under the MIT License.