Blame view

bower_components/l20n/dist/compat/web/l20n-common.js 41.1 KB
0e9aeacd   root   localization l20n
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
  'use strict';
  
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  
  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;
  
  function load(type, url) {
    return new Promise(function (resolve, reject) {
      var xhr = new XMLHttpRequest();
  
      if (xhr.overrideMimeType) {
        xhr.overrideMimeType(type);
      }
  
      xhr.open('GET', url, true);
  
      if (type === 'application/json') {
        xhr.responseType = 'json';
      }
  
      xhr.addEventListener('load', function io_onload(e) {
        if (e.target.status === 200 || e.target.status === 0) {
          resolve(e.target.response || e.target.responseText);
        } else {
          reject(new L10nError('Not found: ' + url));
        }
      });
      xhr.addEventListener('error', reject);
      xhr.addEventListener('timeout', reject);
  
      try {
        xhr.send(null);
      } catch (e) {
        if (e.name === 'NS_ERROR_FILE_NOT_FOUND') {
          reject(new L10nError('Not found: ' + url));
        } else {
          throw e;
        }
      }
    });
  }
  
  var io = {
    extra: function (code, ver, path, type) {
      return navigator.mozApps.getLocalizationResource(code, ver, path, type);
    },
    app: function (code, ver, path, type) {
      switch (type) {
        case 'text':
          return load('text/plain', path);
        case 'json':
          return load('application/json', path);
        default:
          throw new L10nError('Unknown file type: ' + type);
      }
    }
  };
  
a1a3bc73   Luigi Serra   graphs updates
66
67
68
69
70
71
  function fetchResource$1(res, _ref) {
    var code = _ref.code;
    var src = _ref.src;
    var ver = _ref.ver;
  
    var url = res.replace('{locale}', code);
0e9aeacd   root   localization l20n
72
    var type = res.endsWith('.json') ? 'json' : 'text';
a1a3bc73   Luigi Serra   graphs updates
73
    return io[src](code, ver, url, type);
0e9aeacd   root   localization l20n
74
75
  }
  
a1a3bc73   Luigi Serra   graphs updates
76
77
  var KNOWN_MACROS = ['plural'];
  var MAX_PLACEABLE_LENGTH = 2500;
0e9aeacd   root   localization l20n
78
  
a1a3bc73   Luigi Serra   graphs updates
79
80
  var FSI = '⁨';
  var PDI = '⁩';
0e9aeacd   root   localization l20n
81
  
a1a3bc73   Luigi Serra   graphs updates
82
  var resolutionChain = new WeakSet();
0e9aeacd   root   localization l20n
83
  
a1a3bc73   Luigi Serra   graphs updates
84
85
86
87
  function format(ctx, lang, args, entity) {
    if (typeof entity === 'string') {
      return [{}, entity];
    }
0e9aeacd   root   localization l20n
88
  
a1a3bc73   Luigi Serra   graphs updates
89
90
91
    if (resolutionChain.has(entity)) {
      throw new L10nError('Cyclic reference detected');
    }
0e9aeacd   root   localization l20n
92
  
a1a3bc73   Luigi Serra   graphs updates
93
    resolutionChain.add(entity);
0e9aeacd   root   localization l20n
94
  
a1a3bc73   Luigi Serra   graphs updates
95
    var rv = undefined;
0e9aeacd   root   localization l20n
96
  
a1a3bc73   Luigi Serra   graphs updates
97
98
99
100
101
102
103
    try {
      rv = resolveValue({}, ctx, lang, args, entity.value, entity.index);
    } finally {
      resolutionChain.delete(entity);
    }
    return rv;
  }
0e9aeacd   root   localization l20n
104
  
a1a3bc73   Luigi Serra   graphs updates
105
106
107
108
  function resolveIdentifier(ctx, lang, args, id) {
    if (KNOWN_MACROS.indexOf(id) > -1) {
      return [{}, ctx._getMacro(lang, id)];
    }
0e9aeacd   root   localization l20n
109
  
a1a3bc73   Luigi Serra   graphs updates
110
111
112
    if (args && args.hasOwnProperty(id)) {
      if (typeof args[id] === 'string' || typeof args[id] === 'number' && !isNaN(args[id])) {
        return [{}, args[id]];
0e9aeacd   root   localization l20n
113
      } else {
a1a3bc73   Luigi Serra   graphs updates
114
        throw new L10nError('Arg must be a string or a number: ' + id);
0e9aeacd   root   localization l20n
115
      }
a1a3bc73   Luigi Serra   graphs updates
116
    }
0e9aeacd   root   localization l20n
117
  
a1a3bc73   Luigi Serra   graphs updates
118
119
120
    if (id === '__proto__') {
      throw new L10nError('Illegal id: ' + id);
    }
0e9aeacd   root   localization l20n
121
  
a1a3bc73   Luigi Serra   graphs updates
122
    var entity = ctx._getEntity(lang, id);
0e9aeacd   root   localization l20n
123
  
a1a3bc73   Luigi Serra   graphs updates
124
125
126
    if (entity) {
      return format(ctx, lang, args, entity);
    }
0e9aeacd   root   localization l20n
127
  
a1a3bc73   Luigi Serra   graphs updates
128
129
    throw new L10nError('Unknown reference: ' + id);
  }
0e9aeacd   root   localization l20n
130
  
a1a3bc73   Luigi Serra   graphs updates
131
132
133
  function subPlaceable(locals, ctx, lang, args, id) {
    var newLocals = undefined,
        value = undefined;
0e9aeacd   root   localization l20n
134
  
a1a3bc73   Luigi Serra   graphs updates
135
136
    try {
      var _resolveIdentifier = resolveIdentifier(ctx, lang, args, id);
0e9aeacd   root   localization l20n
137
  
a1a3bc73   Luigi Serra   graphs updates
138
139
140
141
142
      newLocals = _resolveIdentifier[0];
      value = _resolveIdentifier[1];
    } catch (err) {
      return [{ error: err }, FSI + '{{ ' + id + ' }}' + PDI];
    }
0e9aeacd   root   localization l20n
143
  
a1a3bc73   Luigi Serra   graphs updates
144
145
146
147
    if (typeof value === 'number') {
      var formatter = ctx._getNumberFormatter(lang);
      return [newLocals, formatter.format(value)];
    }
0e9aeacd   root   localization l20n
148
  
a1a3bc73   Luigi Serra   graphs updates
149
150
151
    if (typeof value === 'string') {
      if (value.length >= MAX_PLACEABLE_LENGTH) {
        throw new L10nError('Too many characters in placeable (' + value.length + ', max allowed is ' + MAX_PLACEABLE_LENGTH + ')');
0e9aeacd   root   localization l20n
152
      }
a1a3bc73   Luigi Serra   graphs updates
153
154
      return [newLocals, FSI + value + PDI];
    }
0e9aeacd   root   localization l20n
155
  
a1a3bc73   Luigi Serra   graphs updates
156
157
    return [{}, FSI + '{{ ' + id + ' }}' + PDI];
  }
0e9aeacd   root   localization l20n
158
  
a1a3bc73   Luigi Serra   graphs updates
159
160
161
162
163
164
165
  function interpolate(locals, ctx, lang, args, arr) {
    return arr.reduce(function (_ref2, cur) {
      var localsSeq = _ref2[0];
      var valueSeq = _ref2[1];
  
      if (typeof cur === 'string') {
        return [localsSeq, valueSeq + cur];
0e9aeacd   root   localization l20n
166
      } else {
a1a3bc73   Luigi Serra   graphs updates
167
        var _subPlaceable = subPlaceable(locals, ctx, lang, args, cur.name);
0e9aeacd   root   localization l20n
168
  
a1a3bc73   Luigi Serra   graphs updates
169
170
171
        var value = _subPlaceable[1];
  
        return [localsSeq, valueSeq + value];
0e9aeacd   root   localization l20n
172
      }
a1a3bc73   Luigi Serra   graphs updates
173
174
    }, [locals, '']);
  }
0e9aeacd   root   localization l20n
175
  
a1a3bc73   Luigi Serra   graphs updates
176
177
178
179
180
181
182
183
  function resolveSelector(ctx, lang, args, expr, index) {
    var selectorName = undefined;
    if (index[0].type === 'call' && index[0].expr.type === 'prop' && index[0].expr.expr.name === 'cldr') {
      selectorName = 'plural';
    } else {
      selectorName = index[0].name;
    }
    var selector = resolveIdentifier(ctx, lang, args, selectorName)[1];
0e9aeacd   root   localization l20n
184
  
a1a3bc73   Luigi Serra   graphs updates
185
186
187
    if (typeof selector !== 'function') {
      return selector;
    }
0e9aeacd   root   localization l20n
188
  
a1a3bc73   Luigi Serra   graphs updates
189
    var argValue = index[0].args ? resolveIdentifier(ctx, lang, args, index[0].args[0].name)[1] : undefined;
0e9aeacd   root   localization l20n
190
  
a1a3bc73   Luigi Serra   graphs updates
191
192
193
194
195
196
197
198
199
200
201
    if (selectorName === 'plural') {
      if (argValue === 0 && 'zero' in expr) {
        return 'zero';
      }
      if (argValue === 1 && 'one' in expr) {
        return 'one';
      }
      if (argValue === 2 && 'two' in expr) {
        return 'two';
      }
    }
0e9aeacd   root   localization l20n
202
  
a1a3bc73   Luigi Serra   graphs updates
203
204
    return selector(argValue);
  }
0e9aeacd   root   localization l20n
205
  
a1a3bc73   Luigi Serra   graphs updates
206
207
208
209
  function resolveValue(locals, ctx, lang, args, expr, index) {
    if (!expr) {
      return [locals, expr];
    }
0e9aeacd   root   localization l20n
210
  
a1a3bc73   Luigi Serra   graphs updates
211
212
213
    if (typeof expr === 'string' || typeof expr === 'boolean' || typeof expr === 'number') {
      return [locals, expr];
    }
0e9aeacd   root   localization l20n
214
  
a1a3bc73   Luigi Serra   graphs updates
215
216
217
    if (Array.isArray(expr)) {
      return interpolate(locals, ctx, lang, args, expr);
    }
0e9aeacd   root   localization l20n
218
  
a1a3bc73   Luigi Serra   graphs updates
219
220
221
222
    if (index) {
      var selector = resolveSelector(ctx, lang, args, expr, index);
      if (selector in expr) {
        return resolveValue(locals, ctx, lang, args, expr[selector]);
0e9aeacd   root   localization l20n
223
      }
a1a3bc73   Luigi Serra   graphs updates
224
    }
0e9aeacd   root   localization l20n
225
  
a1a3bc73   Luigi Serra   graphs updates
226
227
228
229
    var defaultKey = expr.__default || 'other';
    if (defaultKey in expr) {
      return resolveValue(locals, ctx, lang, args, expr[defaultKey]);
    }
0e9aeacd   root   localization l20n
230
  
a1a3bc73   Luigi Serra   graphs updates
231
232
    throw new L10nError('Unresolvable value');
  }
0e9aeacd   root   localization l20n
233
  
a1a3bc73   Luigi Serra   graphs updates
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
  var 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
  };
0e9aeacd   root   localization l20n
406
  
a1a3bc73   Luigi Serra   graphs updates
407
408
409
410
411
412
  function isIn(n, list) {
    return list.indexOf(n) !== -1;
  }
  function isBetween(n, start, end) {
    return typeof n === typeof start && start <= n && n <= end;
  }
0e9aeacd   root   localization l20n
413
  
a1a3bc73   Luigi Serra   graphs updates
414
415
416
  var pluralRules = {
    '0': function () {
      return 'other';
0e9aeacd   root   localization l20n
417
    },
a1a3bc73   Luigi Serra   graphs updates
418
419
420
    '1': function (n) {
      if (isBetween(n % 100, 3, 10)) {
        return 'few';
0e9aeacd   root   localization l20n
421
      }
a1a3bc73   Luigi Serra   graphs updates
422
423
      if (n === 0) {
        return 'zero';
0e9aeacd   root   localization l20n
424
      }
a1a3bc73   Luigi Serra   graphs updates
425
426
      if (isBetween(n % 100, 11, 99)) {
        return 'many';
0e9aeacd   root   localization l20n
427
      }
a1a3bc73   Luigi Serra   graphs updates
428
429
      if (n === 2) {
        return 'two';
0e9aeacd   root   localization l20n
430
      }
a1a3bc73   Luigi Serra   graphs updates
431
432
      if (n === 1) {
        return 'one';
0e9aeacd   root   localization l20n
433
      }
a1a3bc73   Luigi Serra   graphs updates
434
      return 'other';
0e9aeacd   root   localization l20n
435
    },
a1a3bc73   Luigi Serra   graphs updates
436
437
438
    '2': function (n) {
      if (n !== 0 && n % 10 === 0) {
        return 'many';
0e9aeacd   root   localization l20n
439
      }
a1a3bc73   Luigi Serra   graphs updates
440
441
      if (n === 2) {
        return 'two';
0e9aeacd   root   localization l20n
442
      }
a1a3bc73   Luigi Serra   graphs updates
443
444
      if (n === 1) {
        return 'one';
0e9aeacd   root   localization l20n
445
      }
a1a3bc73   Luigi Serra   graphs updates
446
      return 'other';
0e9aeacd   root   localization l20n
447
    },
a1a3bc73   Luigi Serra   graphs updates
448
449
450
    '3': function (n) {
      if (n === 1) {
        return 'one';
0e9aeacd   root   localization l20n
451
      }
a1a3bc73   Luigi Serra   graphs updates
452
      return 'other';
0e9aeacd   root   localization l20n
453
    },
a1a3bc73   Luigi Serra   graphs updates
454
455
456
    '4': function (n) {
      if (isBetween(n, 0, 1)) {
        return 'one';
0e9aeacd   root   localization l20n
457
      }
a1a3bc73   Luigi Serra   graphs updates
458
      return 'other';
0e9aeacd   root   localization l20n
459
    },
a1a3bc73   Luigi Serra   graphs updates
460
461
462
463
464
465
466
467
468
469
470
471
    '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';
0e9aeacd   root   localization l20n
472
      }
a1a3bc73   Luigi Serra   graphs updates
473
      return 'other';
0e9aeacd   root   localization l20n
474
    },
a1a3bc73   Luigi Serra   graphs updates
475
476
477
    '7': function (n) {
      if (n === 2) {
        return 'two';
0e9aeacd   root   localization l20n
478
      }
a1a3bc73   Luigi Serra   graphs updates
479
480
      if (n === 1) {
        return 'one';
0e9aeacd   root   localization l20n
481
      }
a1a3bc73   Luigi Serra   graphs updates
482
      return 'other';
0e9aeacd   root   localization l20n
483
    },
a1a3bc73   Luigi Serra   graphs updates
484
485
486
    '8': function (n) {
      if (isBetween(n, 3, 6)) {
        return 'few';
0e9aeacd   root   localization l20n
487
      }
a1a3bc73   Luigi Serra   graphs updates
488
489
      if (isBetween(n, 7, 10)) {
        return 'many';
0e9aeacd   root   localization l20n
490
      }
a1a3bc73   Luigi Serra   graphs updates
491
492
493
494
495
496
497
      if (n === 2) {
        return 'two';
      }
      if (n === 1) {
        return 'one';
      }
      return 'other';
0e9aeacd   root   localization l20n
498
    },
a1a3bc73   Luigi Serra   graphs updates
499
500
501
    '9': function (n) {
      if (n === 0 || n !== 1 && isBetween(n % 100, 1, 19)) {
        return 'few';
0e9aeacd   root   localization l20n
502
      }
a1a3bc73   Luigi Serra   graphs updates
503
504
505
506
      if (n === 1) {
        return 'one';
      }
      return 'other';
0e9aeacd   root   localization l20n
507
    },
a1a3bc73   Luigi Serra   graphs updates
508
509
510
    '10': function (n) {
      if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) {
        return 'few';
0e9aeacd   root   localization l20n
511
      }
a1a3bc73   Luigi Serra   graphs updates
512
513
      if (n % 10 === 1 && !isBetween(n % 100, 11, 19)) {
        return 'one';
0e9aeacd   root   localization l20n
514
      }
a1a3bc73   Luigi Serra   graphs updates
515
516
517
518
519
      return 'other';
    },
    '11': function (n) {
      if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) {
        return 'few';
0e9aeacd   root   localization l20n
520
      }
a1a3bc73   Luigi Serra   graphs updates
521
522
523
524
525
526
527
      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';
0e9aeacd   root   localization l20n
528
    },
a1a3bc73   Luigi Serra   graphs updates
529
530
531
    '12': function (n) {
      if (isBetween(n, 2, 4)) {
        return 'few';
0e9aeacd   root   localization l20n
532
      }
a1a3bc73   Luigi Serra   graphs updates
533
534
      if (n === 1) {
        return 'one';
0e9aeacd   root   localization l20n
535
      }
a1a3bc73   Luigi Serra   graphs updates
536
537
538
539
540
      return 'other';
    },
    '13': function (n) {
      if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) {
        return 'few';
0e9aeacd   root   localization l20n
541
      }
a1a3bc73   Luigi Serra   graphs updates
542
543
544
545
546
547
548
      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';
0e9aeacd   root   localization l20n
549
    },
a1a3bc73   Luigi Serra   graphs updates
550
551
552
    '14': function (n) {
      if (isBetween(n % 100, 3, 4)) {
        return 'few';
0e9aeacd   root   localization l20n
553
      }
a1a3bc73   Luigi Serra   graphs updates
554
555
      if (n % 100 === 2) {
        return 'two';
0e9aeacd   root   localization l20n
556
      }
a1a3bc73   Luigi Serra   graphs updates
557
558
      if (n % 100 === 1) {
        return 'one';
0e9aeacd   root   localization l20n
559
      }
a1a3bc73   Luigi Serra   graphs updates
560
561
562
563
564
565
566
567
568
569
570
      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';
0e9aeacd   root   localization l20n
571
      }
a1a3bc73   Luigi Serra   graphs updates
572
      return 'other';
0e9aeacd   root   localization l20n
573
    },
a1a3bc73   Luigi Serra   graphs updates
574
575
576
    '16': function (n) {
      if (n % 10 === 1 && n !== 11) {
        return 'one';
0e9aeacd   root   localization l20n
577
      }
a1a3bc73   Luigi Serra   graphs updates
578
579
580
581
582
      return 'other';
    },
    '17': function (n) {
      if (n === 3) {
        return 'few';
0e9aeacd   root   localization l20n
583
      }
a1a3bc73   Luigi Serra   graphs updates
584
585
586
587
588
589
590
591
592
593
594
595
596
      if (n === 0) {
        return 'zero';
      }
      if (n === 6) {
        return 'many';
      }
      if (n === 2) {
        return 'two';
      }
      if (n === 1) {
        return 'one';
      }
      return 'other';
0e9aeacd   root   localization l20n
597
    },
a1a3bc73   Luigi Serra   graphs updates
598
599
600
    '18': function (n) {
      if (n === 0) {
        return 'zero';
0e9aeacd   root   localization l20n
601
      }
a1a3bc73   Luigi Serra   graphs updates
602
603
604
605
      if (isBetween(n, 0, 2) && n !== 0 && n !== 2) {
        return 'one';
      }
      return 'other';
0e9aeacd   root   localization l20n
606
    },
a1a3bc73   Luigi Serra   graphs updates
607
608
609
    '19': function (n) {
      if (isBetween(n, 2, 10)) {
        return 'few';
0e9aeacd   root   localization l20n
610
      }
a1a3bc73   Luigi Serra   graphs updates
611
612
      if (isBetween(n, 0, 1)) {
        return 'one';
0e9aeacd   root   localization l20n
613
      }
a1a3bc73   Luigi Serra   graphs updates
614
      return 'other';
0e9aeacd   root   localization l20n
615
    },
a1a3bc73   Luigi Serra   graphs updates
616
617
618
    '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';
0e9aeacd   root   localization l20n
619
      }
a1a3bc73   Luigi Serra   graphs updates
620
621
      if (n % 1000000 === 0 && n !== 0) {
        return 'many';
0e9aeacd   root   localization l20n
622
      }
a1a3bc73   Luigi Serra   graphs updates
623
624
      if (n % 10 === 2 && !isIn(n % 100, [12, 72, 92])) {
        return 'two';
0e9aeacd   root   localization l20n
625
      }
a1a3bc73   Luigi Serra   graphs updates
626
627
      if (n % 10 === 1 && !isIn(n % 100, [11, 71, 91])) {
        return 'one';
0e9aeacd   root   localization l20n
628
      }
a1a3bc73   Luigi Serra   graphs updates
629
630
631
632
      return 'other';
    },
    '21': function (n) {
      if (n === 0) {
0e9aeacd   root   localization l20n
633
634
        return 'zero';
      }
a1a3bc73   Luigi Serra   graphs updates
635
636
637
638
639
640
641
642
643
644
645
646
647
      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) {
0e9aeacd   root   localization l20n
648
649
        return 'one';
      }
a1a3bc73   Luigi Serra   graphs updates
650
651
652
653
654
655
656
      return 'other';
    },
    '24': function (n) {
      if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) {
        return 'few';
      }
      if (isIn(n, [2, 12])) {
0e9aeacd   root   localization l20n
657
658
        return 'two';
      }
a1a3bc73   Luigi Serra   graphs updates
659
660
661
662
      if (isIn(n, [1, 11])) {
        return 'one';
      }
      return 'other';
0e9aeacd   root   localization l20n
663
    }
a1a3bc73   Luigi Serra   graphs updates
664
  };
0e9aeacd   root   localization l20n
665
  
a1a3bc73   Luigi Serra   graphs updates
666
667
668
669
670
671
672
673
  function getPluralRule(code) {
    var index = locales2rules[code.replace(/-.*$/, '')];
    if (!(index in pluralRules)) {
      return function () {
        return 'other';
      };
    }
    return pluralRules[index];
0e9aeacd   root   localization l20n
674
675
  }
  
a1a3bc73   Luigi Serra   graphs updates
676
677
678
679
680
681
682
  var L20nIntl = typeof Intl !== 'undefined' ? Intl : {
    NumberFormat: function () {
      return {
        format: function (v) {
          return v;
        }
      };
0e9aeacd   root   localization l20n
683
    }
a1a3bc73   Luigi Serra   graphs updates
684
  };
0e9aeacd   root   localization l20n
685
  
a1a3bc73   Luigi Serra   graphs updates
686
687
688
  var Context = (function () {
    function Context(env, langs, resIds) {
      var _this = this;
0e9aeacd   root   localization l20n
689
  
a1a3bc73   Luigi Serra   graphs updates
690
691
692
693
694
695
696
697
      _classCallCheck(this, Context);
  
      this.langs = langs;
      this.resIds = resIds;
      this.env = env;
      this.emit = function (type, evt) {
        return env.emit(type, evt, _this);
      };
0e9aeacd   root   localization l20n
698
699
    }
  
a1a3bc73   Luigi Serra   graphs updates
700
701
702
703
704
705
706
707
    Context.prototype._formatTuple = function _formatTuple(lang, args, entity, id, key) {
      try {
        return format(this, lang, args, entity);
      } catch (err) {
        err.id = key ? id + '::' + key : id;
        err.lang = lang;
        this.emit('resolveerror', err);
        return [{ error: err }, err.id];
0e9aeacd   root   localization l20n
708
      }
a1a3bc73   Luigi Serra   graphs updates
709
    };
0e9aeacd   root   localization l20n
710
  
a1a3bc73   Luigi Serra   graphs updates
711
712
    Context.prototype._formatEntity = function _formatEntity(lang, args, entity, id) {
      var _formatTuple2 = this._formatTuple(lang, args, entity, id);
0e9aeacd   root   localization l20n
713
  
a1a3bc73   Luigi Serra   graphs updates
714
      var value = _formatTuple2[1];
0e9aeacd   root   localization l20n
715
  
a1a3bc73   Luigi Serra   graphs updates
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
      var formatted = {
        value: value,
        attrs: null
      };
  
      if (entity.attrs) {
        formatted.attrs = Object.create(null);
        for (var key in entity.attrs) {
          var _formatTuple3 = this._formatTuple(lang, args, entity.attrs[key], id, key);
  
          var attrValue = _formatTuple3[1];
  
          formatted.attrs[key] = attrValue;
        }
      }
  
      return formatted;
    };
  
    Context.prototype._formatValue = function _formatValue(lang, args, entity, id) {
      return this._formatTuple(lang, args, entity, id)[1];
    };
  
    Context.prototype.fetch = function fetch() {
      var _this2 = this;
0e9aeacd   root   localization l20n
741
  
a1a3bc73   Luigi Serra   graphs updates
742
      var langs = arguments.length <= 0 || arguments[0] === undefined ? this.langs : arguments[0];
0e9aeacd   root   localization l20n
743
  
a1a3bc73   Luigi Serra   graphs updates
744
745
      if (langs.length === 0) {
        return Promise.resolve(langs);
0e9aeacd   root   localization l20n
746
      }
a1a3bc73   Luigi Serra   graphs updates
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
  
      return Promise.all(this.resIds.map(function (resId) {
        return _this2.env._getResource(langs[0], resId);
      })).then(function () {
        return langs;
      });
    };
  
    Context.prototype._resolve = function _resolve(langs, keys, formatter, prevResolved) {
      var _this3 = this;
  
      var lang = langs[0];
  
      if (!lang) {
        return reportMissing.call(this, keys, formatter, prevResolved);
0e9aeacd   root   localization l20n
762
      }
a1a3bc73   Luigi Serra   graphs updates
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
  
      var hasUnresolved = false;
  
      var resolved = keys.map(function (key, i) {
        if (prevResolved && prevResolved[i] !== undefined) {
          return prevResolved[i];
        }
  
        var _ref3 = Array.isArray(key) ? key : [key, undefined];
  
        var id = _ref3[0];
        var args = _ref3[1];
  
        var entity = _this3._getEntity(lang, id);
  
        if (entity) {
          return formatter.call(_this3, lang, args, entity, id);
        }
  
        _this3.emit('notfounderror', new L10nError('"' + id + '"' + ' not found in ' + lang.code, id, lang));
        hasUnresolved = true;
      });
  
      if (!hasUnresolved) {
        return resolved;
0e9aeacd   root   localization l20n
788
      }
a1a3bc73   Luigi Serra   graphs updates
789
790
791
792
793
794
795
796
797
798
799
  
      return this.fetch(langs.slice(1)).then(function (nextLangs) {
        return _this3._resolve(nextLangs, keys, formatter, resolved);
      });
    };
  
    Context.prototype.formatEntities = function formatEntities() {
      var _this4 = this;
  
      for (var _len = arguments.length, keys = Array(_len), _key = 0; _key < _len; _key++) {
        keys[_key] = arguments[_key];
0e9aeacd   root   localization l20n
800
      }
a1a3bc73   Luigi Serra   graphs updates
801
802
803
804
805
806
807
808
809
810
811
  
      return this.fetch().then(function (langs) {
        return _this4._resolve(langs, keys, _this4._formatEntity);
      });
    };
  
    Context.prototype.formatValues = function formatValues() {
      var _this5 = this;
  
      for (var _len2 = arguments.length, keys = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
        keys[_key2] = arguments[_key2];
0e9aeacd   root   localization l20n
812
      }
a1a3bc73   Luigi Serra   graphs updates
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
  
      return this.fetch().then(function (langs) {
        return _this5._resolve(langs, keys, _this5._formatValue);
      });
    };
  
    Context.prototype._getEntity = function _getEntity(lang, id) {
      var cache = this.env.resCache;
  
      for (var i = 0, resId = undefined; resId = this.resIds[i]; i++) {
        var resource = cache.get(resId + lang.code + lang.src);
        if (resource instanceof L10nError) {
          continue;
        }
        if (id in resource) {
          return resource[id];
        }
0e9aeacd   root   localization l20n
830
      }
a1a3bc73   Luigi Serra   graphs updates
831
832
833
834
835
836
      return undefined;
    };
  
    Context.prototype._getNumberFormatter = function _getNumberFormatter(lang) {
      if (!this.env.numberFormatters) {
        this.env.numberFormatters = new Map();
0e9aeacd   root   localization l20n
837
      }
a1a3bc73   Luigi Serra   graphs updates
838
839
840
841
      if (!this.env.numberFormatters.has(lang)) {
        var formatter = L20nIntl.NumberFormat(lang);
        this.env.numberFormatters.set(lang, formatter);
        return formatter;
0e9aeacd   root   localization l20n
842
      }
a1a3bc73   Luigi Serra   graphs updates
843
844
845
846
847
848
849
850
851
      return this.env.numberFormatters.get(lang);
    };
  
    Context.prototype._getMacro = function _getMacro(lang, id) {
      switch (id) {
        case 'plural':
          return getPluralRule(lang.code);
        default:
          return undefined;
0e9aeacd   root   localization l20n
852
      }
a1a3bc73   Luigi Serra   graphs updates
853
854
855
856
857
858
859
860
861
862
863
864
865
    };
  
    return Context;
  })();
  
  function reportMissing(keys, formatter, resolved) {
    var _this6 = this;
  
    var missingIds = new Set();
  
    keys.forEach(function (key, i) {
      if (resolved && resolved[i] !== undefined) {
        return;
0e9aeacd   root   localization l20n
866
      }
a1a3bc73   Luigi Serra   graphs updates
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
      var id = Array.isArray(key) ? key[0] : key;
      missingIds.add(id);
      resolved[i] = formatter === _this6._formatValue ? id : { value: id, attrs: null };
    });
  
    this.emit('notfounderror', new L10nError('"' + Array.from(missingIds).join(', ') + '"' + ' not found in any language', missingIds));
  
    return resolved;
  }
  
  var MAX_PLACEABLES = 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*\}\}/
      };
0e9aeacd   root   localization l20n
895
    },
a1a3bc73   Luigi Serra   graphs updates
896
897
898
899
  
    parse: function (emit, source) {
      if (!this.patterns) {
        this.init();
0e9aeacd   root   localization l20n
900
      }
a1a3bc73   Luigi Serra   graphs updates
901
902
903
904
905
906
907
      this.emit = emit;
  
      var entries = {};
  
      var lines = source.match(this.patterns.entries);
      if (!lines) {
        return entries;
0e9aeacd   root   localization l20n
908
      }
a1a3bc73   Luigi Serra   graphs updates
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
      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;
            }
          }
        }
0e9aeacd   root   localization l20n
930
      }
a1a3bc73   Luigi Serra   graphs updates
931
      return entries;
0e9aeacd   root   localization l20n
932
    },
a1a3bc73   Luigi Serra   graphs updates
933
934
935
936
937
938
939
940
941
942
943
  
    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;
0e9aeacd   root   localization l20n
944
      }
a1a3bc73   Luigi Serra   graphs updates
945
946
947
948
949
  
      var nameElements = name.split('.');
  
      if (nameElements.length > 2) {
        throw this.error('Error in ID: "' + name + '".' + ' Nested attributes are not supported.');
0e9aeacd   root   localization l20n
950
      }
a1a3bc73   Luigi Serra   graphs updates
951
952
953
954
955
956
957
958
959
960
961
  
      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;
0e9aeacd   root   localization l20n
962
      }
a1a3bc73   Luigi Serra   graphs updates
963
964
  
      this.setEntityValue(name, attr, key, this.unescapeString(value), entries);
0e9aeacd   root   localization l20n
965
    },
a1a3bc73   Luigi Serra   graphs updates
966
967
968
969
970
971
972
973
974
975
976
977
  
    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;
0e9aeacd   root   localization l20n
978
      }
a1a3bc73   Luigi Serra   graphs updates
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
  
      if (attr) {
        if (isSimpleNode) {
          var 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;
0e9aeacd   root   localization l20n
994
      }
a1a3bc73   Luigi Serra   graphs updates
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
  
      if (key) {
        isSimpleNode = false;
        if (typeof root[id] === 'string') {
          var 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;
0e9aeacd   root   localization l20n
1007
      }
a1a3bc73   Luigi Serra   graphs updates
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
  
      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;
0e9aeacd   root   localization l20n
1019
      }
0e9aeacd   root   localization l20n
1020
    },
a1a3bc73   Luigi Serra   graphs updates
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
  
    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) {
        throw this.error('Too many placeables (' + placeablesCount + ', max allowed is ' + MAX_PLACEABLES + ')');
0e9aeacd   root   localization l20n
1031
      }
a1a3bc73   Luigi Serra   graphs updates
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
  
      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]);
        }
0e9aeacd   root   localization l20n
1042
      }
a1a3bc73   Luigi Serra   graphs updates
1043
      return complexStr;
0e9aeacd   root   localization l20n
1044
    },
a1a3bc73   Luigi Serra   graphs updates
1045
1046
1047
1048
  
    unescapeString: function (str) {
      if (str.lastIndexOf('\\') !== -1) {
        str = str.replace(this.patterns.controlChars, '$1');
0e9aeacd   root   localization l20n
1049
      }
a1a3bc73   Luigi Serra   graphs updates
1050
1051
1052
      return str.replace(this.patterns.unicode, function (match, token) {
        return String.fromCodePoint(parseInt(token, 16));
      });
0e9aeacd   root   localization l20n
1053
    },
a1a3bc73   Luigi Serra   graphs updates
1054
1055
1056
1057
1058
  
    parseIndex: function (str) {
      var match = str.match(this.patterns.index);
      if (!match) {
        throw new L10nError('Malformed index');
0e9aeacd   root   localization l20n
1059
      }
a1a3bc73   Luigi Serra   graphs updates
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
      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] }];
0e9aeacd   root   localization l20n
1078
      }
a1a3bc73   Luigi Serra   graphs updates
1079
1080
1081
1082
1083
1084
1085
1086
    },
  
    error: function (msg) {
      var type = arguments.length <= 1 || arguments[1] === undefined ? 'parsererror' : arguments[1];
  
      var err = new L10nError(msg);
      if (this.emit) {
        this.emit(type, err);
0e9aeacd   root   localization l20n
1087
      }
a1a3bc73   Luigi Serra   graphs updates
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
      return err;
    }
  };
  
  var MAX_PLACEABLES$1 = 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();
0e9aeacd   root   localization l20n
1103
    },
a1a3bc73   Luigi Serra   graphs updates
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
  
    getResource: function () {
      this.getWS();
      while (this._index < this._length) {
        try {
          this.getEntry();
        } catch (e) {
          if (e instanceof L10nError) {
            this.getJunkEntry();
            if (!this.emit) {
              throw e;
            }
          } else {
            throw e;
          }
        }
  
        if (this._index < this._length) {
          this.getWS();
        }
0e9aeacd   root   localization l20n
1124
      }
a1a3bc73   Luigi Serra   graphs updates
1125
1126
  
      return this.entries;
0e9aeacd   root   localization l20n
1127
    },
a1a3bc73   Luigi Serra   graphs updates
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
  
    getEntry: function () {
      if (this._source[this._index] === '<') {
        ++this._index;
        var id = this.getIdentifier();
        if (this._source[this._index] === '[') {
          ++this._index;
          return this.getEntity(id, this.getItemList(this.getExpression, ']'));
        }
        return this.getEntity(id);
0e9aeacd   root   localization l20n
1138
      }
a1a3bc73   Luigi Serra   graphs updates
1139
1140
1141
  
      if (this._source.startsWith('/*', this._index)) {
        return this.getComment();
0e9aeacd   root   localization l20n
1142
      }
a1a3bc73   Luigi Serra   graphs updates
1143
1144
1145
1146
1147
1148
1149
  
      throw this.error('Invalid entry');
    },
  
    getEntity: function (id, index) {
      if (!this.getRequiredWS()) {
        throw this.error('Expected white space');
0e9aeacd   root   localization l20n
1150
      }
a1a3bc73   Luigi Serra   graphs updates
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
  
      var ch = this._source[this._index];
      var hasIndex = index !== undefined;
      var value = this.getValue(ch, hasIndex, hasIndex);
      var attrs = undefined;
  
      if (value === undefined) {
        if (ch === '>') {
          throw this.error('Expected ">"');
        }
        attrs = this.getAttributes();
      } else {
        var ws1 = this.getRequiredWS();
        if (this._source[this._index] !== '>') {
          if (!ws1) {
            throw this.error('Expected ">"');
          }
          attrs = this.getAttributes();
        }
0e9aeacd   root   localization l20n
1170
      }
a1a3bc73   Luigi Serra   graphs updates
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
  
      ++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: value,
          attrs: attrs,
          index: index
        };
0e9aeacd   root   localization l20n
1185
      }
0e9aeacd   root   localization l20n
1186
    },
a1a3bc73   Luigi Serra   graphs updates
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
  
    getValue: function () {
      var ch = arguments.length <= 0 || arguments[0] === undefined ? this._source[this._index] : arguments[0];
      var index = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
      var required = arguments.length <= 2 || arguments[2] === undefined ? true : arguments[2];
  
      switch (ch) {
        case '\'':
        case '"':
          return this.getString(ch, 1);
        case '{':
          return this.getHash(index);
0e9aeacd   root   localization l20n
1199
      }
a1a3bc73   Luigi Serra   graphs updates
1200
1201
1202
  
      if (required) {
        throw this.error('Unknown value type');
0e9aeacd   root   localization l20n
1203
      }
a1a3bc73   Luigi Serra   graphs updates
1204
1205
  
      return;
0e9aeacd   root   localization l20n
1206
    },
a1a3bc73   Luigi Serra   graphs updates
1207
1208
1209
1210
1211
1212
  
    getWS: function () {
      var cc = this._source.charCodeAt(this._index);
  
      while (cc === 32 || cc === 10 || cc === 9 || cc === 13) {
        cc = this._source.charCodeAt(++this._index);
0e9aeacd   root   localization l20n
1213
      }
0e9aeacd   root   localization l20n
1214
    },
a1a3bc73   Luigi Serra   graphs updates
1215
1216
1217
1218
1219
1220
1221
  
    getRequiredWS: function () {
      var pos = this._index;
      var cc = this._source.charCodeAt(pos);
  
      while (cc === 32 || cc === 10 || cc === 9 || cc === 13) {
        cc = this._source.charCodeAt(++this._index);
0e9aeacd   root   localization l20n
1222
      }
a1a3bc73   Luigi Serra   graphs updates
1223
      return this._index !== pos;
0e9aeacd   root   localization l20n
1224
    },
a1a3bc73   Luigi Serra   graphs updates
1225
1226
1227
1228
1229
1230
1231
1232
1233
  
    getIdentifier: function () {
      var start = this._index;
      var cc = this._source.charCodeAt(this._index);
  
      if (cc >= 97 && cc <= 122 || cc >= 65 && cc <= 90 || cc === 95) {
        cc = this._source.charCodeAt(++this._index);
      } else {
        throw this.error('Identifier has to start with [a-zA-Z_]');
0e9aeacd   root   localization l20n
1234
      }
a1a3bc73   Luigi Serra   graphs updates
1235
1236
1237
  
      while (cc >= 97 && cc <= 122 || cc >= 65 && cc <= 90 || cc >= 48 && cc <= 57 || cc === 95) {
        cc = this._source.charCodeAt(++this._index);
0e9aeacd   root   localization l20n
1238
      }
a1a3bc73   Luigi Serra   graphs updates
1239
1240
  
      return this._source.slice(start, this._index);
0e9aeacd   root   localization l20n
1241
    },
a1a3bc73   Luigi Serra   graphs updates
1242
1243
1244
1245
1246
1247
1248
1249
  
    getUnicodeChar: function () {
      for (var i = 0; i < 4; i++) {
        var cc = this._source.charCodeAt(++this._index);
        if (cc > 96 && cc < 103 || cc > 64 && cc < 71 || cc > 47 && cc < 58) {
          continue;
        }
        throw this.error('Illegal unicode escape sequence');
0e9aeacd   root   localization l20n
1250
      }
a1a3bc73   Luigi Serra   graphs updates
1251
1252
      this._index++;
      return String.fromCharCode(parseInt(this._source.slice(this._index - 4, this._index), 16));
0e9aeacd   root   localization l20n
1253
    },
a1a3bc73   Luigi Serra   graphs updates
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
  
    stringRe: /"|'|{{|\\/g,
    getString: function (opchar, opcharLen) {
      var body = [];
      var placeables = 0;
  
      this._index += opcharLen;
      var start = this._index;
  
      var bufStart = start;
      var buf = '';
  
      while (true) {
        this.stringRe.lastIndex = this._index;
        var 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 - 1) {
            throw this.error('Too many placeables, maximum allowed is ' + MAX_PLACEABLES$1);
          }
          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;
          var 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;
        }
0e9aeacd   root   localization l20n
1317
      }
a1a3bc73   Luigi Serra   graphs updates
1318
1319
1320
  
      if (body.length === 0) {
        return buf + this._source.slice(bufStart, this._index - opcharLen);
0e9aeacd   root   localization l20n
1321
      }
a1a3bc73   Luigi Serra   graphs updates
1322
1323
1324
  
      if (this._index - opcharLen > bufStart || buf.length > 0) {
        body.push(buf + this._source.slice(bufStart, this._index - opcharLen));
0e9aeacd   root   localization l20n
1325
      }
a1a3bc73   Luigi Serra   graphs updates
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
  
      return body;
    },
  
    getAttributes: function () {
      var attrs = Object.create(null);
  
      while (true) {
        this.getAttribute(attrs);
        var ws1 = this.getRequiredWS();
        var ch = this._source.charAt(this._index);
        if (ch === '>') {
          break;
        } else if (!ws1) {
          throw this.error('Expected ">"');
        }
0e9aeacd   root   localization l20n
1342
      }
a1a3bc73   Luigi Serra   graphs updates
1343
1344
      return attrs;
    },
0e9aeacd   root   localization l20n
1345
  
a1a3bc73   Luigi Serra   graphs updates
1346
1347
1348
    getAttribute: function (attrs) {
      var key = this.getIdentifier();
      var index = undefined;
0e9aeacd   root   localization l20n
1349
  
a1a3bc73   Luigi Serra   graphs updates
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
      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();
      var hasIndex = index !== undefined;
      var value = this.getValue(undefined, hasIndex);
0e9aeacd   root   localization l20n
1363
  
a1a3bc73   Luigi Serra   graphs updates
1364
1365
1366
      if (key in attrs) {
        throw this.error('Duplicate attribute "' + key, 'duplicateerror');
      }
0e9aeacd   root   localization l20n
1367
  
a1a3bc73   Luigi Serra   graphs updates
1368
1369
1370
1371
1372
1373
1374
      if (!index && typeof value === 'string') {
        attrs[key] = value;
      } else {
        attrs[key] = {
          value: value,
          index: index
        };
0e9aeacd   root   localization l20n
1375
      }
a1a3bc73   Luigi Serra   graphs updates
1376
    },
0e9aeacd   root   localization l20n
1377
  
a1a3bc73   Luigi Serra   graphs updates
1378
1379
    getHash: function (index) {
      var items = Object.create(null);
0e9aeacd   root   localization l20n
1380
  
a1a3bc73   Luigi Serra   graphs updates
1381
1382
      ++this._index;
      this.getWS();
0e9aeacd   root   localization l20n
1383
  
a1a3bc73   Luigi Serra   graphs updates
1384
      var defKey = undefined;
0e9aeacd   root   localization l20n
1385
  
a1a3bc73   Luigi Serra   graphs updates
1386
1387
1388
1389
1390
1391
      while (true) {
        var _getHashItem = this.getHashItem();
  
        var key = _getHashItem[0];
        var value = _getHashItem[1];
        var def = _getHashItem[2];
0e9aeacd   root   localization l20n
1392
  
a1a3bc73   Luigi Serra   graphs updates
1393
        items[key] = value;
0e9aeacd   root   localization l20n
1394
  
a1a3bc73   Luigi Serra   graphs updates
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
        if (def) {
          if (defKey) {
            throw this.error('Default item redefinition forbidden');
          }
          defKey = key;
        }
        this.getWS();
  
        var 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 "}"');
0e9aeacd   root   localization l20n
1414
1415
1416
        }
      }
  
a1a3bc73   Luigi Serra   graphs updates
1417
1418
1419
1420
1421
      if (defKey) {
        items.__default = defKey;
      } else if (!index) {
        throw this.error('Unresolvable Hash Value');
      }
0e9aeacd   root   localization l20n
1422
  
a1a3bc73   Luigi Serra   graphs updates
1423
1424
      return items;
    },
0e9aeacd   root   localization l20n
1425
  
a1a3bc73   Luigi Serra   graphs updates
1426
1427
1428
1429
1430
    getHashItem: function () {
      var defItem = false;
      if (this._source[this._index] === '*') {
        ++this._index;
        defItem = true;
0e9aeacd   root   localization l20n
1431
1432
      }
  
a1a3bc73   Luigi Serra   graphs updates
1433
1434
1435
1436
1437
1438
1439
      var key = this.getIdentifier();
      this.getWS();
      if (this._source[this._index] !== ':') {
        throw this.error('Expected ":"');
      }
      ++this._index;
      this.getWS();
0e9aeacd   root   localization l20n
1440
  
a1a3bc73   Luigi Serra   graphs updates
1441
1442
      return [key, this.getValue(), defItem];
    },
0e9aeacd   root   localization l20n
1443
  
a1a3bc73   Luigi Serra   graphs updates
1444
1445
1446
1447
    getComment: function () {
      this._index += 2;
      var start = this._index;
      var end = this._source.indexOf('*/', start);
0e9aeacd   root   localization l20n
1448
  
a1a3bc73   Luigi Serra   graphs updates
1449
1450
      if (end === -1) {
        throw this.error('Comment without a closing tag');
0e9aeacd   root   localization l20n
1451
1452
      }
  
a1a3bc73   Luigi Serra   graphs updates
1453
1454
      this._index = end + 2;
    },
0e9aeacd   root   localization l20n
1455
  
a1a3bc73   Luigi Serra   graphs updates
1456
1457
    getExpression: function () {
      var exp = this.getPrimaryExpression();
0e9aeacd   root   localization l20n
1458
  
a1a3bc73   Luigi Serra   graphs updates
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
      while (true) {
        var 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;
        }
      }
0e9aeacd   root   localization l20n
1471
  
a1a3bc73   Luigi Serra   graphs updates
1472
1473
      return exp;
    },
0e9aeacd   root   localization l20n
1474
  
a1a3bc73   Luigi Serra   graphs updates
1475
1476
    getPropertyExpression: function (idref, computed) {
      var exp = undefined;
0e9aeacd   root   localization l20n
1477
  
a1a3bc73   Luigi Serra   graphs updates
1478
1479
1480
1481
1482
1483
      if (computed) {
        this.getWS();
        exp = this.getExpression();
        this.getWS();
        if (this._source[this._index] !== ']') {
          throw this.error('Expected "]"');
0e9aeacd   root   localization l20n
1484
        }
a1a3bc73   Luigi Serra   graphs updates
1485
1486
1487
1488
        ++this._index;
      } else {
        exp = this.getIdentifier();
      }
0e9aeacd   root   localization l20n
1489
  
a1a3bc73   Luigi Serra   graphs updates
1490
1491
1492
1493
1494
1495
1496
      return {
        type: 'prop',
        expr: idref,
        prop: exp,
        cmpt: computed
      };
    },
0e9aeacd   root   localization l20n
1497
  
a1a3bc73   Luigi Serra   graphs updates
1498
1499
    getCallExpression: function (callee) {
      this.getWS();
0e9aeacd   root   localization l20n
1500
  
a1a3bc73   Luigi Serra   graphs updates
1501
1502
1503
1504
1505
1506
      return {
        type: 'call',
        expr: callee,
        args: this.getItemList(this.getExpression, ')')
      };
    },
0e9aeacd   root   localization l20n
1507
  
a1a3bc73   Luigi Serra   graphs updates
1508
1509
    getPrimaryExpression: function () {
      var ch = this._source[this._index];
0e9aeacd   root   localization l20n
1510
  
a1a3bc73   Luigi Serra   graphs updates
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
      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()
          };
      }
    },
0e9aeacd   root   localization l20n
1531
  
a1a3bc73   Luigi Serra   graphs updates
1532
1533
1534
    getItemList: function (callback, closeChar) {
      var items = [];
      var closed = false;
0e9aeacd   root   localization l20n
1535
  
a1a3bc73   Luigi Serra   graphs updates
1536
      this.getWS();
0e9aeacd   root   localization l20n
1537
  
a1a3bc73   Luigi Serra   graphs updates
1538
1539
1540
1541
      if (this._source[this._index] === closeChar) {
        ++this._index;
        closed = true;
      }
0e9aeacd   root   localization l20n
1542
  
a1a3bc73   Luigi Serra   graphs updates
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
      while (!closed) {
        items.push(callback.call(this));
        this.getWS();
        var 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 + '"');
0e9aeacd   root   localization l20n
1558
1559
        }
      }
0e9aeacd   root   localization l20n
1560
  
a1a3bc73   Luigi Serra   graphs updates
1561
1562
      return items;
    },
0e9aeacd   root   localization l20n
1563
  
a1a3bc73   Luigi Serra   graphs updates
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
    getJunkEntry: function () {
      var pos = this._index;
      var nextEntity = this._source.indexOf('<', pos);
      var nextComment = this._source.indexOf('/*', pos);
  
      if (nextEntity === -1) {
        nextEntity = this._length;
      }
      if (nextComment === -1) {
        nextComment = this._length;
0e9aeacd   root   localization l20n
1574
      }
0e9aeacd   root   localization l20n
1575
  
a1a3bc73   Luigi Serra   graphs updates
1576
      var nextEntry = Math.min(nextEntity, nextComment);
0e9aeacd   root   localization l20n
1577
  
a1a3bc73   Luigi Serra   graphs updates
1578
1579
      this._index = nextEntry;
    },
0e9aeacd   root   localization l20n
1580
  
a1a3bc73   Luigi Serra   graphs updates
1581
1582
    error: function (message) {
      var type = arguments.length <= 1 || arguments[1] === undefined ? 'parsererror' : arguments[1];
0e9aeacd   root   localization l20n
1583
  
a1a3bc73   Luigi Serra   graphs updates
1584
      var pos = this._index;
0e9aeacd   root   localization l20n
1585
  
a1a3bc73   Luigi Serra   graphs updates
1586
1587
1588
1589
      var start = this._source.lastIndexOf('<', pos - 1);
      var lastClose = this._source.lastIndexOf('>', pos - 1);
      start = lastClose > start ? lastClose + 1 : start;
      var context = this._source.slice(start, pos + 10);
0e9aeacd   root   localization l20n
1590
  
a1a3bc73   Luigi Serra   graphs updates
1591
1592
1593
1594
1595
1596
1597
1598
      var msg = message + ' at pos ' + pos + ': `' + context + '`';
      var err = new L10nError(msg);
      if (this.emit) {
        this.emit(type, err);
      }
      return err;
    }
  };
0e9aeacd   root   localization l20n
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
  
  function walkEntry(entry, fn) {
    if (typeof entry === 'string') {
      return fn(entry);
    }
  
    var newEntry = Object.create(null);
  
    if (entry.value) {
      newEntry.value = walkValue(entry.value, fn);
    }
  
    if (entry.index) {
      newEntry.index = entry.index;
    }
  
    if (entry.attrs) {
      newEntry.attrs = Object.create(null);
      for (var key in entry.attrs) {
        newEntry.attrs[key] = walkEntry(entry.attrs[key], fn);
      }
    }
  
    return newEntry;
  }
  
  function walkValue(value, fn) {
    if (typeof value === 'string') {
      return fn(value);
    }
  
    if (value.type) {
      return value;
    }
  
    var newValue = Array.isArray(value) ? [] : Object.create(null);
    var keys = Object.keys(value);
  
    for (var i = 0, key = undefined; key = keys[i]; i++) {
      newValue[key] = walkValue(value[key], fn);
    }
  
    return newValue;
  }
  
  function createGetter(id, name) {
    var _pseudo = null;
  
    return function getPseudo() {
      if (_pseudo) {
        return _pseudo;
      }
  
      var reAlphas = /[a-zA-Z]/g;
      var reVowels = /[aeiouAEIOU]/g;
      var reWords = /[^\W0-9_]+/g;
  
      var reExcluded = /(%[EO]?\w|\{\s*.+?\s*\}|&[#\w]+;|<\s*.+?\s*>)/;
  
      var charMaps = {
        'fr-x-psaccent': 'ȦƁƇḒḖƑƓĦĪĴĶĿḾȠǾƤɊŘŞŦŬṼẆẊẎẐ[\\]^_`ȧƀƈḓḗƒɠħīĵķŀḿƞǿƥɋřşŧŭṽẇẋẏẑ',
        'ar-x-psbidi': '∀ԐↃpƎɟפHIſӼ˥WNOԀÒᴚS⊥∩ɅMXʎZ[\\]ᵥ_,ɐqɔpǝɟƃɥıɾʞʅɯuodbɹsʇnʌʍxʎz'
      };
  
      var mods = {
        'fr-x-psaccent': function (val) {
          return val.replace(reVowels, function (match) {
            return match + match.toLowerCase();
          });
        },
  
        'ar-x-psbidi': function (val) {
          return val.replace(reWords, function (match) {
            return '‮' + match + '‬';
          });
        }
      };
  
      var replaceChars = function (map, val) {
        return val.replace(reAlphas, function (match) {
          return map.charAt(match.charCodeAt(0) - 65);
        });
      };
  
      var transform = function (val) {
        return replaceChars(charMaps[id], mods[id](val));
      };
  
      var apply = function (fn, val) {
        if (!val) {
          return val;
        }
  
        var parts = val.split(reExcluded);
        var modified = parts.map(function (part) {
          if (reExcluded.test(part)) {
            return part;
          }
          return fn(part);
        });
        return modified.join('');
      };
  
      return _pseudo = {
        name: transform(name),
        process: function (str) {
          return apply(transform, str);
        }
      };
    };
  }
  
  var pseudo = Object.defineProperties(Object.create(null), {
    'fr-x-psaccent': {
      enumerable: true,
      get: createGetter('fr-x-psaccent', 'Runtime Accented')
    },
    'ar-x-psbidi': {
      enumerable: true,
      get: createGetter('ar-x-psbidi', 'Runtime Bidi')
    }
  });
  
  function emit(listeners) {
a1a3bc73   Luigi Serra   graphs updates
1723
    var _this7 = this;
0e9aeacd   root   localization l20n
1724
  
a1a3bc73   Luigi Serra   graphs updates
1725
1726
    for (var _len3 = arguments.length, args = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
      args[_key3 - 1] = arguments[_key3];
0e9aeacd   root   localization l20n
1727
1728
1729
1730
1731
1732
    }
  
    var type = args.shift();
  
    if (listeners['*']) {
      listeners['*'].slice().forEach(function (listener) {
a1a3bc73   Luigi Serra   graphs updates
1733
        return listener.apply(_this7, args);
0e9aeacd   root   localization l20n
1734
1735
1736
1737
1738
      });
    }
  
    if (listeners[type]) {
      listeners[type].slice().forEach(function (listener) {
a1a3bc73   Luigi Serra   graphs updates
1739
        return listener.apply(_this7, args);
0e9aeacd   root   localization l20n
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
      });
    }
  }
  
  function addEventListener(listeners, type, listener) {
    if (!(type in listeners)) {
      listeners[type] = [];
    }
    listeners[type].push(listener);
  }
  
  function removeEventListener(listeners, type, listener) {
    var typeListeners = listeners[type];
    var pos = typeListeners.indexOf(listener);
    if (pos === -1) {
      return;
    }
  
    typeListeners.splice(pos, 1);
  }
  
0e9aeacd   root   localization l20n
1761
  var Env$1 = (function () {
a1a3bc73   Luigi Serra   graphs updates
1762
    function Env$1(fetchResource) {
0e9aeacd   root   localization l20n
1763
1764
      _classCallCheck(this, Env$1);
  
0e9aeacd   root   localization l20n
1765
1766
      this.fetchResource = fetchResource;
  
a1a3bc73   Luigi Serra   graphs updates
1767
1768
1769
1770
1771
1772
1773
      this.resCache = new Map();
      this.resRefs = new Map();
      this.numberFormatters = null;
      this.parsers = {
        properties: PropertiesParser,
        l20n: L20nParser
      };
0e9aeacd   root   localization l20n
1774
1775
1776
1777
1778
1779
1780
  
      var listeners = {};
      this.emit = emit.bind(this, listeners);
      this.addEventListener = addEventListener.bind(this, listeners);
      this.removeEventListener = removeEventListener.bind(this, listeners);
    }
  
a1a3bc73   Luigi Serra   graphs updates
1781
1782
1783
1784
1785
1786
1787
1788
1789
    Env$1.prototype.createContext = function createContext(langs, resIds) {
      var _this8 = this;
  
      var ctx = new Context(this, langs, resIds);
      resIds.forEach(function (resId) {
        var usedBy = _this8.resRefs.get(resId) || 0;
        _this8.resRefs.set(resId, usedBy + 1);
      });
  
0e9aeacd   root   localization l20n
1790
1791
1792
1793
      return ctx;
    };
  
    Env$1.prototype.destroyContext = function destroyContext(ctx) {
a1a3bc73   Luigi Serra   graphs updates
1794
      var _this9 = this;
0e9aeacd   root   localization l20n
1795
  
a1a3bc73   Luigi Serra   graphs updates
1796
1797
1798
1799
1800
1801
      ctx.resIds.forEach(function (resId) {
        var usedBy = _this9.resRefs.get(resId) || 0;
  
        if (usedBy > 1) {
          return _this9.resRefs.set(resId, usedBy - 1);
        }
0e9aeacd   root   localization l20n
1802
  
a1a3bc73   Luigi Serra   graphs updates
1803
1804
1805
1806
        _this9.resRefs.delete(resId);
        _this9.resCache.forEach(function (val, key) {
          return key.startsWith(resId) ? _this9.resCache.delete(key) : null;
        });
0e9aeacd   root   localization l20n
1807
1808
1809
1810
      });
    };
  
    Env$1.prototype._parse = function _parse(syntax, lang, data) {
a1a3bc73   Luigi Serra   graphs updates
1811
      var _this10 = this;
0e9aeacd   root   localization l20n
1812
  
a1a3bc73   Luigi Serra   graphs updates
1813
      var parser = this.parsers[syntax];
0e9aeacd   root   localization l20n
1814
1815
1816
1817
1818
      if (!parser) {
        return data;
      }
  
      var emit = function (type, err) {
a1a3bc73   Luigi Serra   graphs updates
1819
        return _this10.emit(type, amendError(lang, err));
0e9aeacd   root   localization l20n
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
      };
      return parser.parse.call(parser, emit, data);
    };
  
    Env$1.prototype._create = function _create(lang, entries) {
      if (lang.src !== 'pseudo') {
        return entries;
      }
  
      var pseudoentries = Object.create(null);
      for (var key in entries) {
        pseudoentries[key] = walkEntry(entries[key], pseudo[lang.code].process);
      }
      return pseudoentries;
    };
  
    Env$1.prototype._getResource = function _getResource(lang, res) {
a1a3bc73   Luigi Serra   graphs updates
1837
      var _this11 = this;
0e9aeacd   root   localization l20n
1838
  
a1a3bc73   Luigi Serra   graphs updates
1839
      var cache = this.resCache;
0e9aeacd   root   localization l20n
1840
1841
1842
1843
1844
1845
1846
1847
1848
      var id = res + lang.code + lang.src;
  
      if (cache.has(id)) {
        return cache.get(id);
      }
  
      var syntax = res.substr(res.lastIndexOf('.') + 1);
  
      var saveEntries = function (data) {
a1a3bc73   Luigi Serra   graphs updates
1849
1850
        var entries = _this11._parse(syntax, lang, data);
        cache.set(id, _this11._create(lang, entries));
0e9aeacd   root   localization l20n
1851
1852
1853
1854
      };
  
      var recover = function (err) {
        err.lang = lang;
a1a3bc73   Luigi Serra   graphs updates
1855
        _this11.emit('fetcherror', err);
0e9aeacd   root   localization l20n
1856
1857
1858
        cache.set(id, err);
      };
  
a1a3bc73   Luigi Serra   graphs updates
1859
      var langToFetch = lang.src === 'pseudo' ? { code: 'en-US', src: 'app', ver: lang.ver } : lang;
0e9aeacd   root   localization l20n
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
  
      var resource = this.fetchResource(res, langToFetch).then(saveEntries, recover);
  
      cache.set(id, resource);
  
      return resource;
    };
  
    return Env$1;
  })();
  
0e9aeacd   root   localization l20n
1871
1872
1873
1874
1875
1876
1877
  function amendError(lang, err) {
    err.lang = lang;
    return err;
  }
  
  exports.fetchResource = fetchResource$1;
  exports.Env = Env$1;