EN
Forum

Methodology

Toolbox

Platform

Technologies API

The package includes the following technologies:

keysets

Technology that creates a result that is used by other technologies in the enb-bem-i18n package. Collects data (keysets) for the language specified in the ?.keysets. <lang>.js file based on <lang>.js files.

Options

target

Type: String. Default: ?.keysets.<lang>.js.

The name for saving the result of building the necessary <lang>. js files for the project – a compiled ?.keysets.<lang>.js file.

The ?.keysets.<lang>.js file is an intermediate build result that is later used by the i18n technology.

lang

Type: String. Required option.

The language to build the file for.

Acceptable values:

dirsTarget

Type: String. Default: ?.i18n.

The name of the target for accessing the list of source directories for the build. The list of directories is provided by the files technology in the enb-bem-techs package.

sourceDirSuffixes

Type: String | String[]. Default: ['.i18n'].

The directory suffixes to use for filtering for the build.

Example

var KeysetsTech = require('enb-bem-i18n/techs/keysets'),
    FileProvideTech = require('enb/techs/file-provider'),
    bemTechs = require('enb-bem-techs');

module.exports = function(config) {
    config.setLanguages(['en', 'ru']);

    config.node('bundle', function(node) {
        // Getting the FileList
        node.addTechs([
            [FileProvideTech, { target: '?.bemdecl.js' }],
            [bemTechs.levels, { levels: ['blocks'] }],
            [bemTechs.deps],
            [bemTechs.files]
        ]);

        // Building the keyset files for each language
        node.addTech([KeysetsTech, { lang: '{lang}' }]);
        node.addTarget('?.keysets.{lang}.js');
    });
};

i18n

Builds ?.lang.<lang>.js files for a language based on data from the ?.keysets.<lang>.js files that were obtained as the result of using the keysets technology.

i18n — A build technology that converts data from ?.keysets.<lang>.js files to JavaScript.

The i18n technology initializes the i18n core with data from merged keyset files and returns the i18n function, which can be used from templates or client JavaScript.

For information about the i18n API, see the section i18n API.

Options

target

Type: String. Default: ?.lang.<lang>.js.

Name of the file for saving the result of compiling data from the ?.keysets.<lang>.js file – a compiled ?.lang.<lang>.js file.

lang

Type: String. Required option.

The language to build the file for with the translations.

Acceptable values:

keysetsFile

Type: String. Default: ?.keysets.<lang>.js.

?.keysets.<lang>.js file — The result of running keysets – a set of data (keysets) for the specified language that uses the i18n technology for creating ?.lang.<lang>.js files.

exports

Type: Object. Default: { globals: true: true, commonJS ym: true }.

Configures the method for getting the i18n function.

Possible options:

Example

var I18NTech  = require('enb-bem-i18n/techs/i18n'),
    KeysetsTech = require('enb-bem-i18n/techs/keysets'),
    FileProvideTech = require('enb/techs/file-provider'),
    bemTechs = require('enb-bem-techs');

module.exports = function(config) {
    config.setLanguages(['en', 'ru']);

    config.node('bundle', function(node) {
        // Getting the FileList
        node.addTechs([
            [FileProvideTech, { target: '?.bemdecl.js' }],
            [bemTechs.levels, { levels: ['blocks'] }],
            [bemTechs.deps],
            [bemTechs.files]
        ]);

        // Getting the keyset files for each language
        node.addTech([KeysetsTech, { lang: '{lang}' }]);

        // Building the i18n files for each language
        node.addTech([I18NTech, { lang: '{lang}' }]);
        node.addTarget('?.lang.{lang}.js');
    });
};

keysets-xml

Builds ?.keysets.<lang>.xml files based on ?.keysets.<lang>.js files.

The keysets-xml technology is used for localizing services that use XSLT for templating. It is used for localizing XML pages.

Options

target

Type: String. Default: ?.keysets.{lang}.js.

The resulting XML file.

lang

Type: String. Required option.

The language to build the file for.

Example

var KeysetsTech = require('enb-bem-i18n/techs/keysets'),
    KeysetsXMLTech = require('enb-bem-i18n/techs/keysets-xml'),
    FileProvideTech = require('enb/techs/file-provider'),
    bemTechs = require('enb-bem-techs');

module.exports = function(config) {
    config.setLanguages(['en', 'ru']);

    config.node('bundle', function(node) {
        // Getting the FileList
        node.addTechs([
            [FileProvideTech, { target: '?.bemdecl.js' }],
            [bemTechs.levels, { levels: ['blocks'] }],
            [bemTechs.deps],
            [bemTechs.files]
        ]);

        // Getting the keyset files for each language
        node.addTech([KeysetsTech, { lang: '{lang}' }]);

        // Getting the XML files for each language
        node.addTech([KeysetsXMLTech, { lang: '{lang}' }]);
        node.addTarget('?.keysets.{lang}.js');
    });
};
Rate the article
Report an error on GitHub or correct using prose.io.