(function () { 'use strict'; function L10nError(message, id, lang) { this.name = 'L10nError'; this.message = message; this.id = id; this.lang = lang; } L10nError.prototype = Object.create(Error.prototype); L10nError.prototype.constructor = L10nError; const MAX_PLACEABLES = 100; var L20nParser = { parse: function(emit, string) { this._source = string; this._index = 0; this._length = string.length; this.entries = Object.create(null); this.emit = emit; return this.getResource(); }, getResource: function() { this.getWS(); while (this._index < this._length) { try { this.getEntry(); } catch (e) { if (e instanceof L10nError) { // we want to recover, but we don't need it in entries this.getJunkEntry(); if (!this.emit) { throw e; } } else { throw e; } } if (this._index < this._length) { this.getWS(); } } return this.entries; }, getEntry: function() { if (this._source[this._index] === '<') { ++this._index; const id = this.getIdentifier(); if (this._source[this._index] === '[') { ++this._index; return this.getEntity(id, this.getItemList(this.getExpression, ']')); } return this.getEntity(id); } if (this._source.startsWith('/*', this._index)) { return this.getComment(); } throw this.error('Invalid entry'); }, getEntity: function(id, index) { if (!this.getRequiredWS()) { throw this.error('Expected white space'); } const ch = this._source[this._index]; const hasIndex = index !== undefined; const value = this.getValue(ch, hasIndex, hasIndex); let attrs; if (value === undefined) { if (ch === '>') { throw this.error('Expected ">"'); } attrs = this.getAttributes(); } else { const ws1 = this.getRequiredWS(); if (this._source[this._index] !== '>') { if (!ws1) { throw this.error('Expected ">"'); } attrs = this.getAttributes(); } } // skip '>' ++this._index; if (id in this.entries) { throw this.error('Duplicate entry ID "' + id, 'duplicateerror'); } if (!attrs && !index && typeof value === 'string') { this.entries[id] = value; } else { this.entries[id] = { value, attrs, index }; } }, getValue: function( ch = this._source[this._index], index = false, required = true) { switch (ch) { case '\'': case '"': return this.getString(ch, 1); case '{': return this.getHash(index); } if (required) { throw this.error('Unknown value type'); } return; }, getWS: function() { let cc = this._source.charCodeAt(this._index); // space, \n, \t, \r while (cc === 32 || cc === 10 || cc === 9 || cc === 13) { cc = this._source.charCodeAt(++this._index); } }, getRequiredWS: function() { const pos = this._index; let cc = this._source.charCodeAt(pos); // space, \n, \t, \r while (cc === 32 || cc === 10 || cc === 9 || cc === 13) { cc = this._source.charCodeAt(++this._index); } return this._index !== pos; }, getIdentifier: function() { const start = this._index; let cc = this._source.charCodeAt(this._index); if ((cc >= 97 && cc <= 122) || // a-z (cc >= 65 && cc <= 90) || // A-Z cc === 95) { // _ cc = this._source.charCodeAt(++this._index); } else { throw this.error('Identifier has to start with [a-zA-Z_]'); } while ((cc >= 97 && cc <= 122) || // a-z (cc >= 65 && cc <= 90) || // A-Z (cc >= 48 && cc <= 57) || // 0-9 cc === 95) { // _ cc = this._source.charCodeAt(++this._index); } return this._source.slice(start, this._index); }, getUnicodeChar: function() { for (let i = 0; i < 4; i++) { let cc = this._source.charCodeAt(++this._index); if ((cc > 96 && cc < 103) || // a-f (cc > 64 && cc < 71) || // A-F (cc > 47 && cc < 58)) { // 0-9 continue; } throw this.error('Illegal unicode escape sequence'); } this._index++; return String.fromCharCode( parseInt(this._source.slice(this._index - 4, this._index), 16)); }, stringRe: /"|'|{{|\\/g, getString: function(opchar, opcharLen) { const body = []; let placeables = 0; this._index += opcharLen; const start = this._index; let bufStart = start; let buf = ''; while (true) { this.stringRe.lastIndex = this._index; const match = this.stringRe.exec(this._source); if (!match) { throw this.error('Unclosed string literal'); } if (match[0] === '"' || match[0] === '\'') { if (match[0] !== opchar) { this._index += opcharLen; continue; } this._index = match.index + opcharLen; break; } if (match[0] === '{{') { if (placeables > MAX_PLACEABLES - 1) { throw this.error('Too many placeables, maximum allowed is ' + MAX_PLACEABLES); } placeables++; if (match.index > bufStart || buf.length > 0) { body.push(buf + this._source.slice(bufStart, match.index)); buf = ''; } this._index = match.index + 2; this.getWS(); body.push(this.getExpression()); this.getWS(); this._index += 2; bufStart = this._index; continue; } if (match[0] === '\\') { this._index = match.index + 1; const ch2 = this._source[this._index]; if (ch2 === 'u') { buf += this._source.slice(bufStart, match.index) + this.getUnicodeChar(); } else if (ch2 === opchar || ch2 === '\\') { buf += this._source.slice(bufStart, match.index) + ch2; this._index++; } else if (this._source.startsWith('{{', this._index)) { buf += this._source.slice(bufStart, match.index) + '{{'; this._index += 2; } else { throw this.error('Illegal escape sequence'); } bufStart = this._index; } } if (body.length === 0) { return buf + this._source.slice(bufStart, this._index - opcharLen); } if (this._index - opcharLen > bufStart || buf.length > 0) { body.push(buf + this._source.slice(bufStart, this._index - opcharLen)); } return body; }, getAttributes: function() { const attrs = Object.create(null); while (true) { this.getAttribute(attrs); const ws1 = this.getRequiredWS(); const ch = this._source.charAt(this._index); if (ch === '>') { break; } else if (!ws1) { throw this.error('Expected ">"'); } } return attrs; }, getAttribute: function(attrs) { const key = this.getIdentifier(); let index; if (this._source[this._index]=== '[') { ++this._index; this.getWS(); index = this.getItemList(this.getExpression, ']'); } this.getWS(); if (this._source[this._index] !== ':') { throw this.error('Expected ":"'); } ++this._index; this.getWS(); const hasIndex = index !== undefined; const value = this.getValue(undefined, hasIndex); if (key in attrs) { throw this.error('Duplicate attribute "' + key, 'duplicateerror'); } if (!index && typeof value === 'string') { attrs[key] = value; } else { attrs[key] = { value, index }; } }, getHash: function(index) { const items = Object.create(null); ++this._index; this.getWS(); let defKey; while (true) { const [key, value, def] = this.getHashItem(); items[key] = value; if (def) { if (defKey) { throw this.error('Default item redefinition forbidden'); } defKey = key; } this.getWS(); const comma = this._source[this._index] === ','; if (comma) { ++this._index; this.getWS(); } if (this._source[this._index] === '}') { ++this._index; break; } if (!comma) { throw this.error('Expected "}"'); } } if (defKey) { items.__default = defKey; } else if (!index) { throw this.error('Unresolvable Hash Value'); } return items; }, getHashItem: function() { let defItem = false; if (this._source[this._index] === '*') { ++this._index; defItem = true; } const key = this.getIdentifier(); this.getWS(); if (this._source[this._index] !== ':') { throw this.error('Expected ":"'); } ++this._index; this.getWS(); return [key, this.getValue(), defItem]; }, getComment: function() { this._index += 2; const start = this._index; const end = this._source.indexOf('*/', start); if (end === -1) { throw this.error('Comment without a closing tag'); } this._index = end + 2; }, getExpression: function () { let exp = this.getPrimaryExpression(); while (true) { let ch = this._source[this._index]; if (ch === '.' || ch === '[') { ++this._index; exp = this.getPropertyExpression(exp, ch === '['); } else if (ch === '(') { ++this._index; exp = this.getCallExpression(exp); } else { break; } } return exp; }, getPropertyExpression: function(idref, computed) { let exp; if (computed) { this.getWS(); exp = this.getExpression(); this.getWS(); if (this._source[this._index] !== ']') { throw this.error('Expected "]"'); } ++this._index; } else { exp = this.getIdentifier(); } return { type: 'prop', expr: idref, prop: exp, cmpt: computed }; }, getCallExpression: function(callee) { this.getWS(); return { type: 'call', expr: callee, args: this.getItemList(this.getExpression, ')') }; }, getPrimaryExpression: function() { const ch = this._source[this._index]; switch (ch) { case '$': ++this._index; return { type: 'var', name: this.getIdentifier() }; case '@': ++this._index; return { type: 'glob', name: this.getIdentifier() }; default: return { type: 'id', name: this.getIdentifier() }; } }, getItemList: function(callback, closeChar) { const items = []; let closed = false; this.getWS(); if (this._source[this._index] === closeChar) { ++this._index; closed = true; } while (!closed) { items.push(callback.call(this)); this.getWS(); let ch = this._source.charAt(this._index); switch (ch) { case ',': ++this._index; this.getWS(); break; case closeChar: ++this._index; closed = true; break; default: throw this.error('Expected "," or "' + closeChar + '"'); } } return items; }, getJunkEntry: function() { const pos = this._index; let nextEntity = this._source.indexOf('<', pos); let nextComment = this._source.indexOf('/*', pos); if (nextEntity === -1) { nextEntity = this._length; } if (nextComment === -1) { nextComment = this._length; } let nextEntry = Math.min(nextEntity, nextComment); this._index = nextEntry; }, error: function(message, type = 'parsererror') { const pos = this._index; let start = this._source.lastIndexOf('<', pos - 1); const lastClose = this._source.lastIndexOf('>', pos - 1); start = lastClose > start ? lastClose + 1 : start; const context = this._source.slice(start, pos + 10); const msg = message + ' at pos ' + pos + ': `' + context + '`'; const err = new L10nError(msg); if (this.emit) { this.emit(type, err); } return err; }, }; var MAX_PLACEABLES$1 = 100; var PropertiesParser = { patterns: null, entryIds: null, emit: null, init: function() { this.patterns = { comment: /^\s*#|^\s*$/, entity: /^([^=\s]+)\s*=\s*(.*)$/, multiline: /[^\\]\\$/, index: /\{\[\s*(\w+)(?:\(([^\)]*)\))?\s*\]\}/i, unicode: /\\u([0-9a-fA-F]{1,4})/g, entries: /[^\r\n]+/g, controlChars: /\\([\\\n\r\t\b\f\{\}\"\'])/g, placeables: /\{\{\s*([^\s]*?)\s*\}\}/, }; }, parse: function(emit, source) { if (!this.patterns) { this.init(); } this.emit = emit; var entries = {}; var lines = source.match(this.patterns.entries); if (!lines) { return entries; } for (var i = 0; i < lines.length; i++) { var line = lines[i]; if (this.patterns.comment.test(line)) { continue; } while (this.patterns.multiline.test(line) && i < lines.length) { line = line.slice(0, -1) + lines[++i].trim(); } var entityMatch = line.match(this.patterns.entity); if (entityMatch) { try { this.parseEntity(entityMatch[1], entityMatch[2], entries); } catch (e) { if (!this.emit) { throw e; } } } } return entries; }, parseEntity: function(id, value, entries) { var name, key; var pos = id.indexOf('['); if (pos !== -1) { name = id.substr(0, pos); key = id.substring(pos + 1, id.length - 1); } else { name = id; key = null; } var nameElements = name.split('.'); if (nameElements.length > 2) { throw this.error('Error in ID: "' + name + '".' + ' Nested attributes are not supported.'); } var attr; if (nameElements.length > 1) { name = nameElements[0]; attr = nameElements[1]; if (attr[0] === '$') { throw this.error('Attribute can\'t start with "$"'); } } else { attr = null; } this.setEntityValue(name, attr, key, this.unescapeString(value), entries); }, setEntityValue: function(id, attr, key, rawValue, entries) { var value = rawValue.indexOf('{{') > -1 ? this.parseString(rawValue) : rawValue; var isSimpleValue = typeof value === 'string'; var root = entries; var isSimpleNode = typeof entries[id] === 'string'; if (!entries[id] && (attr || key || !isSimpleValue)) { entries[id] = Object.create(null); isSimpleNode = false; } if (attr) { if (isSimpleNode) { const val = entries[id]; entries[id] = Object.create(null); entries[id].value = val; } if (!entries[id].attrs) { entries[id].attrs = Object.create(null); } if (!entries[id].attrs && !isSimpleValue) { entries[id].attrs[attr] = Object.create(null); } root = entries[id].attrs; id = attr; } if (key) { isSimpleNode = false; if (typeof root[id] === 'string') { const val = root[id]; root[id] = Object.create(null); root[id].index = this.parseIndex(val); root[id].value = Object.create(null); } root = root[id].value; id = key; isSimpleValue = true; } if (isSimpleValue) { if (id in root) { throw this.error('Duplicated id: ' + id); } root[id] = value; } else { if (!root[id]) { root[id] = Object.create(null); } root[id].value = value; } }, parseString: function(str) { var chunks = str.split(this.patterns.placeables); var complexStr = []; var len = chunks.length; var placeablesCount = (len - 1) / 2; if (placeablesCount >= MAX_PLACEABLES$1) { throw this.error('Too many placeables (' + placeablesCount + ', max allowed is ' + MAX_PLACEABLES$1 + ')'); } for (var i = 0; i < chunks.length; i++) { if (chunks[i].length === 0) { continue; } if (i % 2 === 1) { complexStr.push({type: 'idOrVar', name: chunks[i]}); } else { complexStr.push(chunks[i]); } } return complexStr; }, unescapeString: function(str) { if (str.lastIndexOf('\\') !== -1) { str = str.replace(this.patterns.controlChars, '$1'); } return str.replace(this.patterns.unicode, function(match, token) { return String.fromCodePoint(parseInt(token, 16)); }); }, parseIndex: function(str) { var match = str.match(this.patterns.index); if (!match) { throw new L10nError('Malformed index'); } if (match[2]) { return [{ type: 'call', expr: { type: 'prop', expr: { type: 'glob', name: 'cldr' }, prop: 'plural', cmpt: false }, args: [{ type: 'idOrVar', name: match[2] }] }]; } else { return [{type: 'idOrVar', name: match[1]}]; } }, error: function(msg, type = 'parsererror') { const err = new L10nError(msg); if (this.emit) { this.emit(type, err); } return err; } }; const KNOWN_MACROS = ['plural']; const MAX_PLACEABLE_LENGTH = 2500; // Unicode bidi isolation characters const FSI = '\u2068'; const PDI = '\u2069'; const resolutionChain = new WeakSet(); function format(ctx, lang, args, entity) { if (typeof entity === 'string') { return [{}, entity]; } if (resolutionChain.has(entity)) { throw new L10nError('Cyclic reference detected'); } resolutionChain.add(entity); let rv; // if format fails, we want the exception to bubble up and stop the whole // resolving process; however, we still need to remove the entity from the // resolution chain try { rv = resolveValue( {}, ctx, lang, args, entity.value, entity.index); } finally { resolutionChain.delete(entity); } return rv; } function resolveIdentifier(ctx, lang, args, id) { if (KNOWN_MACROS.indexOf(id) > -1) { return [{}, ctx._getMacro(lang, id)]; } if (args && args.hasOwnProperty(id)) { if (typeof args[id] === 'string' || (typeof args[id] === 'number' && !isNaN(args[id]))) { return [{}, args[id]]; } else { throw new L10nError('Arg must be a string or a number: ' + id); } } // XXX: special case for Node.js where still: // '__proto__' in Object.create(null) => true if (id === '__proto__') { throw new L10nError('Illegal id: ' + id); } const entity = ctx._getEntity(lang, id); if (entity) { return format(ctx, lang, args, entity); } throw new L10nError('Unknown reference: ' + id); } function subPlaceable(locals, ctx, lang, args, id) { let newLocals, value; try { [newLocals, value] = resolveIdentifier(ctx, lang, args, id); } catch (err) { return [{ error: err }, FSI + '{{ ' + id + ' }}' + PDI]; } if (typeof value === 'number') { const formatter = ctx._getNumberFormatter(lang); return [newLocals, formatter.format(value)]; } if (typeof value === 'string') { // prevent Billion Laughs attacks if (value.length >= MAX_PLACEABLE_LENGTH) { throw new L10nError('Too many characters in placeable (' + value.length + ', max allowed is ' + MAX_PLACEABLE_LENGTH + ')'); } return [newLocals, FSI + value + PDI]; } return [{}, FSI + '{{ ' + id + ' }}' + PDI]; } function interpolate(locals, ctx, lang, args, arr) { return arr.reduce(function([localsSeq, valueSeq], cur) { if (typeof cur === 'string') { return [localsSeq, valueSeq + cur]; } else { const [, value] = subPlaceable(locals, ctx, lang, args, cur.name); // wrap the substitution in bidi isolate characters return [localsSeq, valueSeq + value]; } }, [locals, '']); } function resolveSelector(ctx, lang, args, expr, index) { //XXX: Dehardcode!!! let selectorName; if (index[0].type === 'call' && index[0].expr.type === 'prop' && index[0].expr.expr.name === 'cldr') { selectorName = 'plural'; } else { selectorName = index[0].name; } const selector = resolveIdentifier(ctx, lang, args, selectorName)[1]; if (typeof selector !== 'function') { // selector is a simple reference to an entity or args return selector; } const argValue = index[0].args ? resolveIdentifier(ctx, lang, args, index[0].args[0].name)[1] : undefined; if (selectorName === 'plural') { // special cases for zero, one, two if they are defined on the hash if (argValue === 0 && 'zero' in expr) { return 'zero'; } if (argValue === 1 && 'one' in expr) { return 'one'; } if (argValue === 2 && 'two' in expr) { return 'two'; } } return selector(argValue); } function resolveValue(locals, ctx, lang, args, expr, index) { if (!expr) { return [locals, expr]; } if (typeof expr === 'string' || typeof expr === 'boolean' || typeof expr === 'number') { return [locals, expr]; } if (Array.isArray(expr)) { return interpolate(locals, ctx, lang, args, expr); } // otherwise, it's a dict if (index) { // try to use the index in order to select the right dict member const selector = resolveSelector(ctx, lang, args, expr, index); if (selector in expr) { return resolveValue(locals, ctx, lang, args, expr[selector]); } } // if there was no index or no selector was found, try the default // XXX 'other' is an artifact from Gaia const defaultKey = expr.__default || 'other'; if (defaultKey in expr) { return resolveValue(locals, ctx, lang, args, expr[defaultKey]); } throw new L10nError('Unresolvable value'); } const locales2rules = { 'af': 3, 'ak': 4, 'am': 4, 'ar': 1, 'asa': 3, 'az': 0, 'be': 11, 'bem': 3, 'bez': 3, 'bg': 3, 'bh': 4, 'bm': 0, 'bn': 3, 'bo': 0, 'br': 20, 'brx': 3, 'bs': 11, 'ca': 3, 'cgg': 3, 'chr': 3, 'cs': 12, 'cy': 17, 'da': 3, 'de': 3, 'dv': 3, 'dz': 0, 'ee': 3, 'el': 3, 'en': 3, 'eo': 3, 'es': 3, 'et': 3, 'eu': 3, 'fa': 0, 'ff': 5, 'fi': 3, 'fil': 4, 'fo': 3, 'fr': 5, 'fur': 3, 'fy': 3, 'ga': 8, 'gd': 24, 'gl': 3, 'gsw': 3, 'gu': 3, 'guw': 4, 'gv': 23, 'ha': 3, 'haw': 3, 'he': 2, 'hi': 4, 'hr': 11, 'hu': 0, 'id': 0, 'ig': 0, 'ii': 0, 'is': 3, 'it': 3, 'iu': 7, 'ja': 0, 'jmc': 3, 'jv': 0, 'ka': 0, 'kab': 5, 'kaj': 3, 'kcg': 3, 'kde': 0, 'kea': 0, 'kk': 3, 'kl': 3, 'km': 0, 'kn': 0, 'ko': 0, 'ksb': 3, 'ksh': 21, 'ku': 3, 'kw': 7, 'lag': 18, 'lb': 3, 'lg': 3, 'ln': 4, 'lo': 0, 'lt': 10, 'lv': 6, 'mas': 3, 'mg': 4, 'mk': 16, 'ml': 3, 'mn': 3, 'mo': 9, 'mr': 3, 'ms': 0, 'mt': 15, 'my': 0, 'nah': 3, 'naq': 7, 'nb': 3, 'nd': 3, 'ne': 3, 'nl': 3, 'nn': 3, 'no': 3, 'nr': 3, 'nso': 4, 'ny': 3, 'nyn': 3, 'om': 3, 'or': 3, 'pa': 3, 'pap': 3, 'pl': 13, 'ps': 3, 'pt': 3, 'rm': 3, 'ro': 9, 'rof': 3, 'ru': 11, 'rwk': 3, 'sah': 0, 'saq': 3, 'se': 7, 'seh': 3, 'ses': 0, 'sg': 0, 'sh': 11, 'shi': 19, 'sk': 12, 'sl': 14, 'sma': 7, 'smi': 7, 'smj': 7, 'smn': 7, 'sms': 7, 'sn': 3, 'so': 3, 'sq': 3, 'sr': 11, 'ss': 3, 'ssy': 3, 'st': 3, 'sv': 3, 'sw': 3, 'syr': 3, 'ta': 3, 'te': 3, 'teo': 3, 'th': 0, 'ti': 4, 'tig': 3, 'tk': 3, 'tl': 4, 'tn': 3, 'to': 0, 'tr': 0, 'ts': 3, 'tzm': 22, 'uk': 11, 'ur': 3, 've': 3, 'vi': 0, 'vun': 3, 'wa': 4, 'wae': 3, 'wo': 0, 'xh': 3, 'xog': 3, 'yo': 0, 'zh': 0, 'zu': 3 }; // utility functions for plural rules methods function isIn(n, list) { return list.indexOf(n) !== -1; } function isBetween(n, start, end) { return typeof n === typeof start && start <= n && n <= end; } // list of all plural rules methods: // map an integer to the plural form name to use const pluralRules = { '0': function() { return 'other'; }, '1': function(n) { if ((isBetween((n % 100), 3, 10))) { return 'few'; } if (n === 0) { return 'zero'; } if ((isBetween((n % 100), 11, 99))) { return 'many'; } if (n === 2) { return 'two'; } if (n === 1) { return 'one'; } return 'other'; }, '2': function(n) { if (n !== 0 && (n % 10) === 0) { return 'many'; } if (n === 2) { return 'two'; } if (n === 1) { return 'one'; } return 'other'; }, '3': function(n) { if (n === 1) { return 'one'; } return 'other'; }, '4': function(n) { if ((isBetween(n, 0, 1))) { return 'one'; } return 'other'; }, '5': function(n) { if ((isBetween(n, 0, 2)) && n !== 2) { return 'one'; } return 'other'; }, '6': function(n) { if (n === 0) { return 'zero'; } if ((n % 10) === 1 && (n % 100) !== 11) { return 'one'; } return 'other'; }, '7': function(n) { if (n === 2) { return 'two'; } if (n === 1) { return 'one'; } return 'other'; }, '8': function(n) { if ((isBetween(n, 3, 6))) { return 'few'; } if ((isBetween(n, 7, 10))) { return 'many'; } if (n === 2) { return 'two'; } if (n === 1) { return 'one'; } return 'other'; }, '9': function(n) { if (n === 0 || n !== 1 && (isBetween((n % 100), 1, 19))) { return 'few'; } if (n === 1) { return 'one'; } return 'other'; }, '10': function(n) { if ((isBetween((n % 10), 2, 9)) && !(isBetween((n % 100), 11, 19))) { return 'few'; } if ((n % 10) === 1 && !(isBetween((n % 100), 11, 19))) { return 'one'; } return 'other'; }, '11': function(n) { if ((isBetween((n % 10), 2, 4)) && !(isBetween((n % 100), 12, 14))) { return 'few'; } if ((n % 10) === 0 || (isBetween((n % 10), 5, 9)) || (isBetween((n % 100), 11, 14))) { return 'many'; } if ((n % 10) === 1 && (n % 100) !== 11) { return 'one'; } return 'other'; }, '12': function(n) { if ((isBetween(n, 2, 4))) { return 'few'; } if (n === 1) { return 'one'; } return 'other'; }, '13': function(n) { if ((isBetween((n % 10), 2, 4)) && !(isBetween((n % 100), 12, 14))) { return 'few'; } if (n !== 1 && (isBetween((n % 10), 0, 1)) || (isBetween((n % 10), 5, 9)) || (isBetween((n % 100), 12, 14))) { return 'many'; } if (n === 1) { return 'one'; } return 'other'; }, '14': function(n) { if ((isBetween((n % 100), 3, 4))) { return 'few'; } if ((n % 100) === 2) { return 'two'; } if ((n % 100) === 1) { return 'one'; } return 'other'; }, '15': function(n) { if (n === 0 || (isBetween((n % 100), 2, 10))) { return 'few'; } if ((isBetween((n % 100), 11, 19))) { return 'many'; } if (n === 1) { return 'one'; } return 'other'; }, '16': function(n) { if ((n % 10) === 1 && n !== 11) { return 'one'; } return 'other'; }, '17': function(n) { if (n === 3) { return 'few'; } if (n === 0) { return 'zero'; } if (n === 6) { return 'many'; } if (n === 2) { return 'two'; } if (n === 1) { return 'one'; } return 'other'; }, '18': function(n) { if (n === 0) { return 'zero'; } if ((isBetween(n, 0, 2)) && n !== 0 && n !== 2) { return 'one'; } return 'other'; }, '19': function(n) { if ((isBetween(n, 2, 10))) { return 'few'; } if ((isBetween(n, 0, 1))) { return 'one'; } return 'other'; }, '20': function(n) { if ((isBetween((n % 10), 3, 4) || ((n % 10) === 9)) && !( isBetween((n % 100), 10, 19) || isBetween((n % 100), 70, 79) || isBetween((n % 100), 90, 99) )) { return 'few'; } if ((n % 1000000) === 0 && n !== 0) { return 'many'; } if ((n % 10) === 2 && !isIn((n % 100), [12, 72, 92])) { return 'two'; } if ((n % 10) === 1 && !isIn((n % 100), [11, 71, 91])) { return 'one'; } return 'other'; }, '21': function(n) { if (n === 0) { return 'zero'; } if (n === 1) { return 'one'; } return 'other'; }, '22': function(n) { if ((isBetween(n, 0, 1)) || (isBetween(n, 11, 99))) { return 'one'; } return 'other'; }, '23': function(n) { if ((isBetween((n % 10), 1, 2)) || (n % 20) === 0) { return 'one'; } return 'other'; }, '24': function(n) { if ((isBetween(n, 3, 10) || isBetween(n, 13, 19))) { return 'few'; } if (isIn(n, [2, 12])) { return 'two'; } if (isIn(n, [1, 11])) { return 'one'; } return 'other'; } }; function getPluralRule(code) { // return a function that gives the plural form name for a given integer const index = locales2rules[code.replace(/-.*$/, '')]; if (!(index in pluralRules)) { return function() { return 'other'; }; } return pluralRules[index]; } function MockContext(entries) { this._getNumberFormatter = function() { return { format: function(value) { return value; } }; }; this._getEntity = function(lang, id) { return entries[id]; }; this._getMacro = function(lang, id) { switch(id) { case 'plural': return getPluralRule(lang.code); default: return undefined; } }; } this.L20n = { MockContext, L20nParser, PropertiesParser, format }; })();