function lang(key) {
    return __lang[key] !== undefined ? __lang[key] : '{'+key+'}';
}

lang.num = function(s, num, opts) {
    var defaultOpts = {
        format: true,
        formatDelim: ' ',
        lang: 'ru'
    };
    opts = Object.assign({}, defaultOpts, opts || {});

    if (typeof s === 'string')
        s = get(s);

    var word = 2;
    switch (opts.lang) {
        case 'ru':
            var n = num % 100;
            if (n > 19)
                n %= 10;

            if (n === 1) {
                word = 0;
            } else if (n >= 2 && n <= 4) {
                word = 1;
            } else if (num === 0 && s.length === 4) {
                word = 3;
            } else {
                word = 2;
            }
            break;

        default:
            if (num === 0  && s.length === 4) {
                word = 3;
            } else {
                word = num === 1 ? 0 : 1;
            }
            break;
    }

    // if zero
    if (word === 3)
        return s[3];

    if (typeof opts.format === 'function') {
        num = opts.format(num)
    }

    return sprintf(s[word], num)
}

window.__lang = {};