1.0.3 • Published 6 years ago

@cjssdk/gettext v1.0.3

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

STB SDK localization

build status npm version dependencies status devDependencies status Gitter RunKit

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 @cjssdk/gettext

Usage

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('@cjssdk/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 DEVELOP which 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

@cjssdk/gettext is released under the MIT License.