PageSourceSearch

https://web.rosknroll.fi/rosknroll/js/globalize/globalize/message.js

js rosknroll.fi collected 2026-09-26 03:00:31 UTC 62,460 bytes, 2,022 lines download raw bytes

vendor: 43,540 bytes, lines 1-1474
1/**
2 * Globalize v1.0.0
3 *
4 * http://github.com/jquery/globalize
5 *
6 * Copyright jQuery Foundation and other contributors
7 * Released under the MIT license
8 * http://jquery.org/license
9 *
10 * Date: 2015-04-23T12:02Z
11 */
12/*!
13 * Globalize v1.0.0 2015-04-23T12:02Z Released under the MIT license
14 * http://git.io/TrdQbw
15 */
16(function( root, factory ) {
17
18	// UMD returnExports
19	if ( typeof define === "function" && define.amd ) {
20
21		// AMD
22		define([
23			"cldr",
24			"../globalize",
25			"cldr/event"
26		], factory );
27	} else if ( typeof exports === "object" ) {
28
29		// Node, CommonJS
30		module.exports = factory( require( "cldrjs" ), require( "globalize" ) );
31	} else {
32
33		// Extend global
34		factory( root.Cldr, root.Globalize );
35	}
36}(this, function( Cldr, Globalize ) {
37
38var alwaysArray = Globalize._alwaysArray,
39	isPlainObject = Globalize._isPlainObject,
40	validate = Globalize._validate,
41	validateDefaultLocale = Globalize._validateDefaultLocale,
42	validateParameterPresence = Globalize._validateParameterPresence,
43	validateParameterType = Globalize._validateParameterType,
44	validateParameterTypePlainObject = Globalize._validateParameterTypePlainObject;
45var MessageFormat;
46/* jshint ignore:start */
47MessageFormat = (function() {
48MessageFormat._parse = (function() {
49
50  /*
51   * Generated by PEG.js 0.8.0.
52   *
53   * http://pegjs.majda.cz/
54   */
55
56  function peg$subclass(child, parent) {
57    function ctor() { this.constructor = child; }
58    ctor.prototype = parent.prototype;
59    child.prototype = new ctor();
60  }
61
62  function SyntaxError(message, expected, found, offset, line, column) {
63    this.message  = message;
64    this.expected = expected;
65    this.found    = found;
66    this.offset   = offset;
67    this.line     = line;
68    this.column   = column;
69
70    this.name     = "SyntaxError";
71  }
72
73  peg$subclass(SyntaxError, Error);
74
75  function parse(input) {
76    var options = arguments.length > 1 ? arguments[1] : {},
77
78        peg$FAILED = {},
79
80        peg$startRuleFunctions = { start: peg$parsestart },
81        peg$startRuleFunction  = peg$parsestart,
82
83        peg$c0 = [],
84        peg$c1 = function(st) {
85              return { type: 'messageFormatPattern', statements: st };
86            },
87        peg$c2 = peg$FAILED,
88        peg$c3 = "{",
89        peg$c4 = { type: "literal", value: "{", description: "\"{\"" },
90        peg$c5 = null,
91        peg$c6 = ",",
92        peg$c7 = { type: "literal", value: ",", description: "\",\"" },
93        peg$c8 = "}",
94        peg$c9 = { type: "literal", value: "}", description: "\"}\"" },
95        peg$c10 = function(argIdx, efmt) {
96              var res = {
97                type: "messageFormatElement",
98                argumentIndex: argIdx
99              };
100              if (efmt && efmt.length) {
101                res.elementFormat = efmt[1];
102              } else {
103                res.output = true;
104              }
105              return res;
106            },
107        peg$c11 = "plural",
108        peg$c12 = { type: "literal", value: "plural", description: "\"plural\"" },
109        peg$c13 = function(t, s) {
110              return { type: "elementFormat", key: t, val: s };
111            },
112        peg$c14 = "selectordinal",
113        peg$c15 = { type: "literal", value: "selectordinal", description: "\"selectordinal\"" },
114        peg$c16 = "select",
115        peg$c17 = { type: "literal", value: "select", description: "\"select\"" },
116        peg$c18 = function(t, p) {
117              return { type: "elementFormat", key: t, val: p };
118            },
119        peg$c19 = function(op, pf) {
120              return { type: "pluralFormatPattern", pluralForms: pf, offset: op || 0 };
121            },
122        peg$c20 = "offset",
123        peg$c21 = { type: "literal", value: "offset", description: "\"offset\"" },
124        peg$c22 = ":",
125        peg$c23 = { type: "literal", value: ":", description: "\":\"" },
126        peg$c24 = function(d) { return d; },
127        peg$c25 = function(k, mfp) {
128              return { key: k, val: mfp };
129            },
130        peg$c26 = function(i) { return i; },
131        peg$c27 = "=",
132        peg$c28 = { type: "literal", value: "=", description: "\"=\"" },
133        peg$c29 = function(pf) { return { type: "selectFormatPattern", pluralForms: pf }; },
134        peg$c30 = function(p) { return p; },
135        peg$c31 = "#",
136        peg$c32 = { type: "literal", value: "#", description: "\"#\"" },
137        peg$c33 = function() { return {type: 'octothorpe'}; },
138        peg$c34 = function(s) { return { type: "string", val: s.join('') }; },
139        peg$c35 = { type: "other", description: "identifier" },
140        peg$c36 = /^[0-9a-zA-Z$_]/,
141        peg$c37 = { type: "class", value: "[0-9a-zA-Z$_]", description: "[0-9a-zA-Z$_]" },
142        peg$c38 = /^[^ \t\n\r,.+={}]/,
143        peg$c39 = { type: "class", value: "[^ \\t\\n\\r,.+={}]", description: "[^ \\t\\n\\r,.+={}]" },
144        peg$c40 = function(s) { return s; },
145        peg$c41 = function(chars) { return chars.join(''); },
146        peg$c42 = /^[^{}#\\\0-\x1F� \t\n\r]/,
147        peg$c43 = { type: "class", value: "[^{}#\\\\\\0-\\x1F� \\t\\n\\r]", description: "[^{}#\\\\\\0-\\x1F� \\t\\n\\r]" },
148        peg$c44 = function(x) { return x; },
149        peg$c45 = "\\\\",
150        peg$c46 = { type: "literal", value: "\\\\", description: "\"\\\\\\\\\"" },
151        peg$c47 = function() { return "\\"; },
152        peg$c48 = "\\#",
153        peg$c49 = { type: "literal", value: "\\#", description: "\"\\\\#\"" },
154        peg$c50 = function() { return "#"; },
155        peg$c51 = "\\{",
156        peg$c52 = { type: "literal", value: "\\{", description: "\"\\\\{\"" },
157        peg$c53 = function() { return "\u007B"; },
158        peg$c54 = "\\}",
159        peg$c55 = { type: "literal", value: "\\}", description: "\"\\\\}\"" },
160        peg$c56 = function() { return "\u007D"; },
161        peg$c57 = "\\u",
162        peg$c58 = { type: "literal", value: "\\u", description: "\"\\\\u\"" },
163        peg$c59 = function(h1, h2, h3, h4) {
164              return String.fromCharCode(parseInt("0x" + h1 + h2 + h3 + h4));
165            },
166        peg$c60 = /^[0-9]/,
167        peg$c61 = { type: "class", value: "[0-9]", description: "[0-9]" },
168        peg$c62 = function(ds) {
169            //the number might start with 0 but must not be interpreted as an octal number
170            //Hence, the base is passed to parseInt explicitely
171            return parseInt((ds.join('')), 10);
172          },
173        peg$c63 = /^[0-9a-fA-F]/,
174        peg$c64 = { type: "class", value: "[0-9a-fA-F]", description: "[0-9a-fA-F]" },
175        peg$c65 = { type: "other", description: "whitespace" },
176        peg$c66 = function(w) { return w.join(''); },
177        peg$c67 = /^[ \t\n\r]/,
178        peg$c68 = { type: "class", value: "[ \\t\\n\\r]", description: "[ \\t\\n\\r]" },
179
180        peg$currPos          = 0,
181        peg$reportedPos      = 0,
182        peg$cachedPos        = 0,
183        peg$cachedPosDetails = { line: 1, column: 1, seenCR: false },
184        peg$maxFailPos       = 0,
185        peg$maxFailExpected  = [],
186        peg$silentFails      = 0,
187
188        peg$result;
189
190    if ("startRule" in options) {
191      if (!(options.startRule in peg$startRuleFunctions)) {
192        throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
193      }
194
195      peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
196    }
197
198    function text() {
199      return input.substring(peg$reportedPos, peg$currPos);
200    }
201
202    function offset() {
203      return peg$reportedPos;
204    }
205
206    function line() {
207      return peg$computePosDetails(peg$reportedPos).line;
208    }
209
210    function column() {
211      return peg$computePosDetails(peg$reportedPos).column;
212    }
213
214    function expected(description) {
215      throw peg$buildException(
216        null,
217        [{ type: "other", description: description }],
218        peg$reportedPos
219      );
220    }
221
222    function error(message) {
223      throw peg$buildException(message, null, peg$reportedPos);
224    }
225
226    function peg$computePosDetails(pos) {
227      function advance(details, startPos, endPos) {
228        var p, ch;
229
230        for (p = startPos; p < endPos; p++) {
231          ch = input.charAt(p);
232          if (ch === "\n") {
233            if (!details.seenCR) { details.line++; }
234            details.column = 1;
235            details.seenCR = false;
236          } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") {
237            details.line++;
238            details.column = 1;
239            details.seenCR = true;
240          } else {
241            details.column++;
242            details.seenCR = false;
243          }
244        }
245      }
246
247      if (peg$cachedPos !== pos) {
248        if (peg$cachedPos > pos) {
249          peg$cachedPos = 0;
250          peg$cachedPosDetails = { line: 1, column: 1, seenCR: false };
251        }
252        advance(peg$cachedPosDetails, peg$cachedPos, pos);
253        peg$cachedPos = pos;
254      }
255
256      return peg$cachedPosDetails;
257    }
258
259    function peg$fail(expected) {
260      if (peg$currPos < peg$maxFailPos) { return; }
261
262      if (peg$currPos > peg$maxFailPos) {
263        peg$maxFailPos = peg$currPos;
264        peg$maxFailExpected = [];
265      }
266
267      peg$maxFailExpected.push(expected);
268    }
269
270    function peg$buildException(message, expected, pos) {
271      function cleanupExpected(expected) {
272        var i = 1;
273
274        expected.sort(function(a, b) {
275          if (a.description < b.description) {
276            return -1;
277          } else if (a.description > b.description) {
278            return 1;
279          } else {
280            return 0;
281          }
282        });
283
284        while (i < expected.length) {
285          if (expected[i - 1] === expected[i]) {
286            expected.splice(i, 1);
287          } else {
288            i++;
289          }
290        }
291      }
292
293      function buildMessage(expected, found) {
294        function stringEscape(s) {
295          function hex(ch) { return ch.charCodeAt(0).toString(16).toUpperCase(); }
296
297          return s
298            .replace(/\\/g,   '\\\\')
299            .replace(/"/g,    '\\"')
300            .replace(/\x08/g, '\\b')
301            .replace(/\t/g,   '\\t')
302            .replace(/\n/g,   '\\n')
303            .replace(/\f/g,   '\\f')
304            .replace(/\r/g,   '\\r')
305            .replace(/[\x00-\x07\x0B\x0E\x0F]/g, function(ch) { return '\\x0' + hex(ch); })
306            .replace(/[\x10-\x1F\x80-\xFF]/g,    function(ch) { return '\\x'  + hex(ch); })
307            .replace(/[\u0180-\u0FFF]/g,         function(ch) { return '\\u0' + hex(ch); })
308            .replace(/[\u1080-\uFFFF]/g,         function(ch) { return '\\u'  + hex(ch); });
309        }
310
311        var expectedDescs = new Array(expected.length),
312            expectedDesc, foundDesc, i;
313
314        for (i = 0; i < expected.length; i++) {
315          expectedDescs[i] = expected[i].description;
316        }
317
318        expectedDesc = expected.length > 1
319          ? expectedDescs.slice(0, -1).join(", ")
320              + " or "
321              + expectedDescs[expected.length - 1]
322          : expectedDescs[0];
323
324        foundDesc = found ? "\"" + stringEscape(found) + "\"" : "end of input";
325
326        return "Expected " + expectedDesc + " but " + foundDesc + " found.";
327      }
328
329      var posDetails = peg$computePosDetails(pos),
330          found      = pos < input.length ? input.charAt(pos) : null;
331
332      if (expected !== null) {
333        cleanupExpected(expected);
334      }
335
336      return new SyntaxError(
337        message !== null ? message : buildMessage(expected, found),
338        expected,
339        found,
340        pos,
341        posDetails.line,
342        posDetails.column
343      );
344    }
345
346    function peg$parsestart() {
347      var s0;
348
349      s0 = peg$parsemessageFormatPattern();
350
351      return s0;
352    }
353
354    function peg$parsemessageFormatPattern() {
355      var s0, s1, s2;
356
357      s0 = peg$currPos;
358      s1 = [];
359      s2 = peg$parsemessageFormatElement();
360      if (s2 === peg$FAILED) {
361        s2 = peg$parsestring();
362        if (s2 === peg$FAILED) {
363          s2 = peg$parseoctothorpe();
364        }
365      }
366      while (s2 !== peg$FAILED) {
367        s1.push(s2);
368        s2 = peg$parsemessageFormatElement();
369        if (s2 === peg$FAILED) {
370          s2 = peg$parsestring();
371          if (s2 === peg$FAILED) {
372            s2 = peg$parseoctothorpe();
373          }
374        }
375      }
376      if (s1 !== peg$FAILED) {
377        peg$reportedPos = s0;
378        s1 = peg$c1(s1);
379      }
380      s0 = s1;
381
382      return s0;
383    }
384
385    function peg$parsemessageFormatElement() {
386      var s0, s1, s2, s3, s4, s5, s6;
387
388      s0 = peg$currPos;
389      if (input.charCodeAt(peg$currPos) === 123) {
390        s1 = peg$c3;
391        peg$currPos++;
392      } else {
393        s1 = peg$FAILED;
394        if (peg$silentFails === 0) { peg$fail(peg$c4); }
395      }
396      if (s1 !== peg$FAILED) {
397        s2 = peg$parse_();
398        if (s2 !== peg$FAILED) {
399          s3 = peg$parseid();
400          if (s3 !== peg$FAILED) {
401            s4 = peg$currPos;
402            if (input.charCodeAt(peg$currPos) === 44) {
403              s5 = peg$c6;
404              peg$currPos++;
405            } else {
406              s5 = peg$FAILED;
407              if (peg$silentFails === 0) { peg$fail(peg$c7); }
408            }
409            if (s5 !== peg$FAILED) {
410              s6 = peg$parseelementFormat();
411              if (s6 !== peg$FAILED) {
412                s5 = [s5, s6];
413                s4 = s5;
414              } else {
415                peg$currPos = s4;
416                s4 = peg$c2;
417              }
418            } else {
419              peg$currPos = s4;
420              s4 = peg$c2;
421            }
422            if (s4 === peg$FAILED) {
423              s4 = peg$c5;
424            }
425            if (s4 !== peg$FAILED) {
426              s5 = peg$parse_();
427              if (s5 !== peg$FAILED) {
428                if (input.charCodeAt(peg$currPos) === 125) {
429                  s6 = peg$c8;
430                  peg$currPos++;
431                } else {
432                  s6 = peg$FAILED;
433                  if (peg$silentFails === 0) { peg$fail(peg$c9); }
434                }
435                if (s6 !== peg$FAILED) {
436                  peg$reportedPos = s0;
437                  s1 = peg$c10(s3, s4);
438                  s0 = s1;
439                } else {
440                  peg$currPos = s0;
441                  s0 = peg$c2;
442                }
443              } else {
444                peg$currPos = s0;
445                s0 = peg$c2;
446              }
447            } else {
448              peg$currPos = s0;
449              s0 = peg$c2;
450            }
451          } else {
452            peg$currPos = s0;
453            s0 = peg$c2;
454          }
455        } else {
456          peg$currPos = s0;
457          s0 = peg$c2;
458        }
459      } else {
460        peg$currPos = s0;
461        s0 = peg$c2;
462      }
463
464      return s0;
465    }
466
467    function peg$parseelementFormat() {
468      var s0, s1, s2, s3, s4, s5, s6, s7;
469
470      s0 = peg$currPos;
471      s1 = peg$parse_();
472      if (s1 !== peg$FAILED) {
473        if (input.substr(peg$currPos, 6) === peg$c11) {
474          s2 = peg$c11;
475          peg$currPos += 6;
476        } else {
477          s2 = peg$FAILED;
478          if (peg$silentFails === 0) { peg$fail(peg$c12); }
479        }
480        if (s2 !== peg$FAILED) {
481          s3 = peg$parse_();
482          if (s3 !== peg$FAILED) {
483            if (input.charCodeAt(peg$currPos) === 44) {
484              s4 = peg$c6;
485              peg$currPos++;
486            } else {
487              s4 = peg$FAILED;
488              if (peg$silentFails === 0) { peg$fail(peg$c7); }
489            }
490            if (s4 !== peg$FAILED) {
491              s5 = peg$parse_();
492              if (s5 !== peg$FAILED) {
493                s6 = peg$parsepluralFormatPattern();
494                if (s6 !== peg$FAILED) {
495                  s7 = peg$parse_();
496                  if (s7 !== peg$FAILED) {
497                    peg$reportedPos = s0;
498                    s1 = peg$c13(s2, s6);
499                    s0 = s1;
500                  } else {
501                    peg$currPos = s0;
502                    s0 = peg$c2;
503                  }
504                } else {
505                  peg$currPos = s0;
506                  s0 = peg$c2;
507                }
508              } else {
509                peg$currPos = s0;
510                s0 = peg$c2;
511              }
512            } else {
513              peg$currPos = s0;
514              s0 = peg$c2;
515            }
516          } else {
517            peg$currPos = s0;
518            s0 = peg$c2;
519          }
520        } else {
521          peg$currPos = s0;
522          s0 = peg$c2;
523        }
524      } else {
525        peg$currPos = s0;
526        s0 = peg$c2;
527      }
528      if (s0 === peg$FAILED) {
529        s0 = peg$currPos;
530        s1 = peg$parse_();
531        if (s1 !== peg$FAILED) {
532          if (input.substr(peg$currPos, 13) === peg$c14) {
533            s2 = peg$c14;
534            peg$currPos += 13;
535          } else {
536            s2 = peg$FAILED;
537            if (peg$silentFails === 0) { peg$fail(peg$c15); }
538          }
539          if (s2 !== peg$FAILED) {
540            s3 = peg$parse_();
541            if (s3 !== peg$FAILED) {
542              if (input.charCodeAt(peg$currPos) === 44) {
543                s4 = peg$c6;
544                peg$currPos++;
545              } else {
546                s4 = peg$FAILED;
547                if (peg$silentFails === 0) { peg$fail(peg$c7); }
548              }
549              if (s4 !== peg$FAILED) {
550                s5 = peg$parse_();
551                if (s5 !== peg$FAILED) {
552                  s6 = peg$parsepluralFormatPattern();
553                  if (s6 !== peg$FAILED) {
554                    s7 = peg$parse_();
555                    if (s7 !== peg$FAILED) {
556                      peg$reportedPos = s0;
557                      s1 = peg$c13(s2, s6);
558                      s0 = s1;
559                    } else {
560                      peg$currPos = s0;
561                      s0 = peg$c2;
562                    }
563                  } else {
564                    peg$currPos = s0;
565                    s0 = peg$c2;
566                  }
567                } else {
568                  peg$currPos = s0;
569                  s0 = peg$c2;
570                }
571              } else {
572                peg$currPos = s0;
573                s0 = peg$c2;
574              }
575            } else {
576              peg$currPos = s0;
577              s0 = peg$c2;
578            }
579          } else {
580            peg$currPos = s0;
581            s0 = peg$c2;
582          }
583        } else {
584          peg$currPos = s0;
585          s0 = peg$c2;
586        }
587        if (s0 === peg$FAILED) {
588          s0 = peg$currPos;
589          s1 = peg$parse_();
590          if (s1 !== peg$FAILED) {
591            if (input.substr(peg$currPos, 6) === peg$c16) {
592              s2 = peg$c16;
593              peg$currPos += 6;
594            } else {
595              s2 = peg$FAILED;
596              if (peg$silentFails === 0) { peg$fail(peg$c17); }
597            }
598            if (s2 !== peg$FAILED) {
599              s3 = peg$parse_();
600              if (s3 !== peg$FAILED) {
601                if (input.charCodeAt(peg$currPos) === 44) {
602                  s4 = peg$c6;
603                  peg$currPos++;
604                } else {
605                  s4 = peg$FAILED;
606                  if (peg$silentFails === 0) { peg$fail(peg$c7); }
607                }
608                if (s4 !== peg$FAILED) {
609                  s5 = peg$parse_();
610                  if (s5 !== peg$FAILED) {
611                    s6 = peg$parseselectFormatPattern();
612                    if (s6 !== peg$FAILED) {
613                      s7 = peg$parse_();
614                      if (s7 !== peg$FAILED) {
615                        peg$reportedPos = s0;
616                        s1 = peg$c13(s2, s6);
617                        s0 = s1;
618                      } else {
619                        peg$currPos = s0;
620                        s0 = peg$c2;
621                      }
622                    } else {
623                      peg$currPos = s0;
624                      s0 = peg$c2;
625                    }
626                  } else {
627                    peg$currPos = s0;
628                    s0 = peg$c2;
629                  }
630                } else {
631                  peg$currPos = s0;
632                  s0 = peg$c2;
633                }
634              } else {
635                peg$currPos = s0;
636                s0 = peg$c2;
637              }
638            } else {
639              peg$currPos = s0;
640              s0 = peg$c2;
641            }
642          } else {
643            peg$currPos = s0;
644            s0 = peg$c2;
645          }
646          if (s0 === peg$FAILED) {
647            s0 = peg$currPos;
648            s1 = peg$parse_();
649            if (s1 !== peg$FAILED) {
650              s2 = peg$parseid();
651              if (s2 !== peg$FAILED) {
652                s3 = [];
653                s4 = peg$parseargStylePattern();
654                while (s4 !== peg$FAILED) {
655                  s3.push(s4);
656                  s4 = peg$parseargStylePattern();
657                }
658                if (s3 !== peg$FAILED) {
659                  peg$reportedPos = s0;
660                  s1 = peg$c18(s2, s3);
661                  s0 = s1;
662                } else {
663                  peg$currPos = s0;
664                  s0 = peg$c2;
665                }
666              } else {
667                peg$currPos = s0;
668                s0 = peg$c2;
669              }
670            } else {
671              peg$currPos = s0;
672              s0 = peg$c2;
673            }
674          }
675        }
676      }
677
678      return s0;
679    }
680
681    function peg$parsepluralFormatPattern() {
682      var s0, s1, s2, s3;
683
684      s0 = peg$currPos;
685      s1 = peg$parseoffsetPattern();
686      if (s1 === peg$FAILED) {
687        s1 = peg$c5;
688      }
689      if (s1 !== peg$FAILED) {
690        s2 = [];
691        s3 = peg$parsepluralForm();
692        if (s3 !== peg$FAILED) {
693          while (s3 !== peg$FAILED) {
694            s2.push(s3);
695            s3 = peg$parsepluralForm();
696          }
697        } else {
698          s2 = peg$c2;
699        }
700        if (s2 !== peg$FAILED) {
701          peg$reportedPos = s0;
702          s1 = peg$c19(s1, s2);
703          s0 = s1;
704        } else {
705          peg$currPos = s0;
706          s0 = peg$c2;
707        }
708      } else {
709        peg$currPos = s0;
710        s0 = peg$c2;
711      }
712
713      return s0;
714    }
715
716    function peg$parseoffsetPattern() {
717      var s0, s1, s2, s3, s4, s5, s6, s7;
718
719      s0 = peg$currPos;
720      s1 = peg$parse_();
721      if (s1 !== peg$FAILED) {
722        if (input.substr(peg$currPos, 6) === peg$c20) {
723          s2 = peg$c20;
724          peg$currPos += 6;
725        } else {
726          s2 = peg$FAILED;
727          if (peg$silentFails === 0) { peg$fail(peg$c21); }
728        }
729        if (s2 !== peg$FAILED) {
730          s3 = peg$parse_();
731          if (s3 !== peg$FAILED) {
732            if (input.charCodeAt(peg$currPos) === 58) {
733              s4 = peg$c22;
734              peg$currPos++;
735            } else {
736              s4 = peg$FAILED;
737              if (peg$silentFails === 0) { peg$fail(peg$c23); }
738            }
739            if (s4 !== peg$FAILED) {
740              s5 = peg$parse_();
741              if (s5 !== peg$FAILED) {
742                s6 = peg$parsedigits();
743                if (s6 !== peg$FAILED) {
744                  s7 = peg$parse_();
745                  if (s7 !== peg$FAILED) {
746                    peg$reportedPos = s0;
747                    s1 = peg$c24(s6);
748                    s0 = s1;
749                  } else {
750                    peg$currPos = s0;
751                    s0 = peg$c2;
752                  }
753                } else {
754                  peg$currPos = s0;
755                  s0 = peg$c2;
756                }
757              } else {
758                peg$currPos = s0;
759                s0 = peg$c2;
760              }
761            } else {
762              peg$currPos = s0;
763              s0 = peg$c2;
764            }
765          } else {
766            peg$currPos = s0;
767            s0 = peg$c2;
768          }
769        } else {
770          peg$currPos = s0;
771          s0 = peg$c2;
772        }
773      } else {
774        peg$currPos = s0;
775        s0 = peg$c2;
776      }
777
778      return s0;
779    }
780
781    function peg$parsepluralForm() {
782      var s0, s1, s2, s3, s4, s5, s6, s7, s8;
783
784      s0 = peg$currPos;
785      s1 = peg$parse_();
786      if (s1 !== peg$FAILED) {
787        s2 = peg$parsepluralKey();
788        if (s2 !== peg$FAILED) {
789          s3 = peg$parse_();
790          if (s3 !== peg$FAILED) {
791            if (input.charCodeAt(peg$currPos) === 123) {
792              s4 = peg$c3;
793              peg$currPos++;
794            } else {
795              s4 = peg$FAILED;
796              if (peg$silentFails === 0) { peg$fail(peg$c4); }
797            }
798            if (s4 !== peg$FAILED) {
799              s5 = peg$parse_();
800              if (s5 !== peg$FAILED) {
801                s6 = peg$parsemessageFormatPattern();
802                if (s6 !== peg$FAILED) {
803                  s7 = peg$parse_();
804                  if (s7 !== peg$FAILED) {
805                    if (input.charCodeAt(peg$currPos) === 125) {
806                      s8 = peg$c8;
807                      peg$currPos++;
808                    } else {
809                      s8 = peg$FAILED;
810                      if (peg$silentFails === 0) { peg$fail(peg$c9); }
811                    }
812                    if (s8 !== peg$FAILED) {
813                      peg$reportedPos = s0;
814                      s1 = peg$c25(s2, s6);
815                      s0 = s1;
816                    } else {
817                      peg$currPos = s0;
818                      s0 = peg$c2;
819                    }
820                  } else {
821                    peg$currPos = s0;
822                    s0 = peg$c2;
823                  }
824                } else {
825                  peg$currPos = s0;
826                  s0 = peg$c2;
827                }
828              } else {
829                peg$currPos = s0;
830                s0 = peg$c2;
831              }
832            } else {
833              peg$currPos = s0;
834              s0 = peg$c2;
835            }
836          } else {
837            peg$currPos = s0;
838            s0 = peg$c2;
839          }
840        } else {
841          peg$currPos = s0;
842          s0 = peg$c2;
843        }
844      } else {
845        peg$currPos = s0;
846        s0 = peg$c2;
847      }
848
849      return s0;
850    }
851
852    function peg$parsepluralKey() {
853      var s0, s1, s2;
854
855      s0 = peg$currPos;
856      s1 = peg$parseid();
857      if (s1 !== peg$FAILED) {
858        peg$reportedPos = s0;
859        s1 = peg$c26(s1);
860      }
861      s0 = s1;
862      if (s0 === peg$FAILED) {
863        s0 = peg$currPos;
864        if (input.charCodeAt(peg$currPos) === 61) {
865          s1 = peg$c27;
866          peg$currPos++;
867        } else {
868          s1 = peg$FAILED;
869          if (peg$silentFails === 0) { peg$fail(peg$c28); }
870        }
871        if (s1 !== peg$FAILED) {
872          s2 = peg$parsedigits();
873          if (s2 !== peg$FAILED) {
874            peg$reportedPos = s0;
875            s1 = peg$c24(s2);
876            s0 = s1;
877          } else {
878            peg$currPos = s0;
879            s0 = peg$c2;
880          }
881        } else {
882          peg$currPos = s0;
883          s0 = peg$c2;
884        }
885      }
886
887      return s0;
888    }
889
890    function peg$parseselectFormatPattern() {
891      var s0, s1, s2;
892
893      s0 = peg$currPos;
894      s1 = [];
895      s2 = peg$parseselectForm();
896      if (s2 !== peg$FAILED) {
897        while (s2 !== peg$FAILED) {
898          s1.push(s2);
899          s2 = peg$parseselectForm();
900        }
901      } else {
902        s1 = peg$c2;
903      }
904      if (s1 !== peg$FAILED) {
905        peg$reportedPos = s0;
906        s1 = peg$c29(s1);
907      }
908      s0 = s1;
909
910      return s0;
911    }
912
913    function peg$parseselectForm() {
914      var s0, s1, s2, s3, s4, s5, s6, s7, s8;
915
916      s0 = peg$currPos;
917      s1 = peg$parse_();
918      if (s1 !== peg$FAILED) {
919        s2 = peg$parseid();
920        if (s2 !== peg$FAILED) {
921          s3 = peg$parse_();
922          if (s3 !== peg$FAILED) {
923            if (input.charCodeAt(peg$currPos) === 123) {
924              s4 = peg$c3;
925              peg$currPos++;
926            } else {
927              s4 = peg$FAILED;
928              if (peg$silentFails === 0) { peg$fail(peg$c4); }
929            }
930            if (s4 !== peg$FAILED) {
931              s5 = peg$parse_();
932              if (s5 !== peg$FAILED) {
933                s6 = peg$parsemessageFormatPattern();
934                if (s6 !== peg$FAILED) {
935                  s7 = peg$parse_();
936                  if (s7 !== peg$FAILED) {
937                    if (input.charCodeAt(peg$currPos) === 125) {
938                      s8 = peg$c8;
939                      peg$currPos++;
940                    } else {
941                      s8 = peg$FAILED;
942                      if (peg$silentFails === 0) { peg$fail(peg$c9); }
943                    }
944                    if (s8 !== peg$FAILED) {
945                      peg$reportedPos = s0;
946                      s1 = peg$c25(s2, s6);
947                      s0 = s1;
948                    } else {
949                      peg$currPos = s0;
950                      s0 = peg$c2;
951                    }
952                  } else {
953                    peg$currPos = s0;
954                    s0 = peg$c2;
955                  }
956                } else {
957                  peg$currPos = s0;
958                  s0 = peg$c2;
959                }
960              } else {
961                peg$currPos = s0;
962                s0 = peg$c2;
963              }
964            } else {
965              peg$currPos = s0;
966              s0 = peg$c2;
967            }
968          } else {
969            peg$currPos = s0;
970            s0 = peg$c2;
971          }
972        } else {
973          peg$currPos = s0;
974          s0 = peg$c2;
975        }
976      } else {
977        peg$currPos = s0;
978        s0 = peg$c2;
979      }
980
981      return s0;
982    }
983
984    function peg$parseargStylePattern() {
985      var s0, s1, s2, s3, s4, s5;
986
987      s0 = peg$currPos;
988      s1 = peg$parse_();
989      if (s1 !== peg$FAILED) {
990        if (input.charCodeAt(peg$currPos) === 44) {
991          s2 = peg$c6;
992          peg$currPos++;
993        } else {
994          s2 = peg$FAILED;
995          if (peg$silentFails === 0) { peg$fail(peg$c7); }
996        }
997        if (s2 !== peg$FAILED) {
998          s3 = peg$parse_();
999          if (s3 !== peg$FAILED) {
1000            s4 = peg$parseid();
1001            if (s4 !== peg$FAILED) {
1002              s5 = peg$parse_();
1003              if (s5 !== peg$FAILED) {
1004                peg$reportedPos = s0;
1005                s1 = peg$c30(s4);
1006                s0 = s1;
1007              } else {
1008                peg$currPos = s0;
1009                s0 = peg$c2;
1010              }
1011            } else {
1012              peg$currPos = s0;
1013              s0 = peg$c2;
1014            }
1015          } else {
1016            peg$currPos = s0;
1017            s0 = peg$c2;
1018          }
1019        } else {
1020          peg$currPos = s0;
1021          s0 = peg$c2;
1022        }
1023      } else {
1024        peg$currPos = s0;
1025        s0 = peg$c2;
1026      }
1027
1028      return s0;
1029    }
1030
1031    function peg$parseoctothorpe() {
1032      var s0, s1;
1033
1034      s0 = peg$currPos;
1035      if (input.charCodeAt(peg$currPos) === 35) {
1036        s1 = peg$c31;
1037        peg$currPos++;
1038      } else {
1039        s1 = peg$FAILED;
1040        if (peg$silentFails === 0) { peg$fail(peg$c32); }
1041      }
1042      if (s1 !== peg$FAILED) {
1043        peg$reportedPos = s0;
1044        s1 = peg$c33();
1045      }
1046      s0 = s1;
1047
1048      return s0;
1049    }
1050
1051    function peg$parsestring() {
1052      var s0, s1, s2;
1053
1054      s0 = peg$currPos;
1055      s1 = [];
1056      s2 = peg$parsechars();
1057      if (s2 === peg$FAILED) {
1058        s2 = peg$parsewhitespace();
1059      }
1060      if (s2 !== peg$FAILED) {
1061        while (s2 !== peg$FAILED) {
1062          s1.push(s2);
1063          s2 = peg$parsechars();
1064          if (s2 === peg$FAILED) {
1065            s2 = peg$parsewhitespace();
1066          }
1067        }
1068      } else {
1069        s1 = peg$c2;
1070      }
1071      if (s1 !== peg$FAILED) {
1072        peg$reportedPos = s0;
1073        s1 = peg$c34(s1);
1074      }
1075      s0 = s1;
1076
1077      return s0;
1078    }
1079
1080    function peg$parseid() {
1081      var s0, s1, s2, s3, s4, s5, s6;
1082
1083      peg$silentFails++;
1084      s0 = peg$currPos;
1085      s1 = peg$parse_();
1086      if (s1 !== peg$FAILED) {
1087        s2 = peg$currPos;
1088        s3 = peg$currPos;
1089        if (peg$c36.test(input.charAt(peg$currPos))) {
1090          s4 = input.charAt(peg$currPos);
1091          peg$currPos++;
1092        } else {
1093          s4 = peg$FAILED;
1094          if (peg$silentFails === 0) { peg$fail(peg$c37); }
1095        }
1096        if (s4 !== peg$FAILED) {
1097          s5 = [];
1098          if (peg$c38.test(input.charAt(peg$currPos))) {
1099            s6 = input.charAt(peg$currPos);
1100            peg$currPos++;
1101          } else {
1102            s6 = peg$FAILED;
1103            if (peg$silentFails === 0) { peg$fail(peg$c39); }
1104          }
1105          while (s6 !== peg$FAILED) {
1106            s5.push(s6);
1107            if (peg$c38.test(input.charAt(peg$currPos))) {
1108              s6 = input.charAt(peg$currPos);
1109              peg$currPos++;
1110            } else {
1111              s6 = peg$FAILED;
1112              if (peg$silentFails === 0) { peg$fail(peg$c39); }
1113            }
1114          }
1115          if (s5 !== peg$FAILED) {
1116            s4 = [s4, s5];
1117            s3 = s4;
1118          } else {
1119            peg$currPos = s3;
1120            s3 = peg$c2;
1121          }
1122        } else {
1123          peg$currPos = s3;
1124          s3 = peg$c2;
1125        }
1126        if (s3 !== peg$FAILED) {
1127          s3 = input.substring(s2, peg$currPos);
1128        }
1129        s2 = s3;
1130        if (s2 !== peg$FAILED) {
1131          s3 = peg$parse_();
1132          if (s3 !== peg$FAILED) {
1133            peg$reportedPos = s0;
1134            s1 = peg$c40(s2);
1135            s0 = s1;
1136          } else {
1137            peg$currPos = s0;
1138            s0 = peg$c2;
1139          }
1140        } else {
1141          peg$currPos = s0;
1142          s0 = peg$c2;
1143        }
1144      } else {
1145        peg$currPos = s0;
1146        s0 = peg$c2;
1147      }
1148      peg$silentFails--;
1149      if (s0 === peg$FAILED) {
1150        s1 = peg$FAILED;
1151        if (peg$silentFails === 0) { peg$fail(peg$c35); }
1152      }
1153
1154      return s0;
1155    }
1156
1157    function peg$parsechars() {
1158      var s0, s1, s2;
1159
1160      s0 = peg$currPos;
1161      s1 = [];
1162      s2 = peg$parsechar();
1163      if (s2 !== peg$FAILED) {
1164        while (s2 !== peg$FAILED) {
1165          s1.push(s2);
1166          s2 = peg$parsechar();
1167        }
1168      } else {
1169        s1 = peg$c2;
1170      }
1171      if (s1 !== peg$FAILED) {
1172        peg$reportedPos = s0;
1173        s1 = peg$c41(s1);
1174      }
1175      s0 = s1;
1176
1177      return s0;
1178    }
1179
1180    function peg$parsechar() {
1181      var s0, s1, s2, s3, s4, s5;
1182
1183      s0 = peg$currPos;
1184      if (peg$c42.test(input.charAt(peg$currPos))) {
1185        s1 = input.charAt(peg$currPos);
1186        peg$currPos++;
1187      } else {
1188        s1 = peg$FAILED;
1189        if (peg$silentFails === 0) { peg$fail(peg$c43); }
1190      }
1191      if (s1 !== peg$FAILED) {
1192        peg$reportedPos = s0;
1193        s1 = peg$c44(s1);
1194      }
1195      s0 = s1;
1196      if (s0 === peg$FAILED) {
1197        s0 = peg$currPos;
1198        if (input.substr(peg$currPos, 2) === peg$c45) {
1199          s1 = peg$c45;
1200          peg$currPos += 2;
1201        } else {
1202          s1 = peg$FAILED;
1203          if (peg$silentFails === 0) { peg$fail(peg$c46); }
1204        }
1205        if (s1 !== peg$FAILED) {
1206          peg$reportedPos = s0;
1207          s1 = peg$c47();
1208        }
1209        s0 = s1;
1210        if (s0 === peg$FAILED) {
1211          s0 = peg$currPos;
1212          if (input.substr(peg$currPos, 2) === peg$c48) {
1213            s1 = peg$c48;
1214            peg$currPos += 2;
1215          } else {
1216            s1 = peg$FAILED;
1217            if (peg$silentFails === 0) { peg$fail(peg$c49); }
1218          }
1219          if (s1 !== peg$FAILED) {
1220            peg$reportedPos = s0;
1221            s1 = peg$c50();
1222          }
1223          s0 = s1;
1224          if (s0 === peg$FAILED) {
1225            s0 = peg$currPos;
1226            if (input.substr(peg$currPos, 2) === peg$c51) {
1227              s1 = peg$c51;
1228              peg$currPos += 2;
1229            } else {
1230              s1 = peg$FAILED;
1231              if (peg$silentFails === 0) { peg$fail(peg$c52); }
1232            }
1233            if (s1 !== peg$FAILED) {
1234              peg$reportedPos = s0;
1235              s1 = peg$c53();
1236            }
1237            s0 = s1;
1238            if (s0 === peg$FAILED) {
1239              s0 = peg$currPos;
1240              if (input.substr(peg$currPos, 2) === peg$c54) {
1241                s1 = peg$c54;
1242                peg$currPos += 2;
1243              } else {
1244                s1 = peg$FAILED;
1245                if (peg$silentFails === 0) { peg$fail(peg$c55); }
1246              }
1247              if (s1 !== peg$FAILED) {
1248                peg$reportedPos = s0;
1249                s1 = peg$c56();
1250              }
1251              s0 = s1;
1252              if (s0 === peg$FAILED) {
1253                s0 = peg$currPos;
1254                if (input.substr(peg$currPos, 2) === peg$c57) {
1255                  s1 = peg$c57;
1256                  peg$currPos += 2;
1257                } else {
1258                  s1 = peg$FAILED;
1259                  if (peg$silentFails === 0) { peg$fail(peg$c58); }
1260                }
1261                if (s1 !== peg$FAILED) {
1262                  s2 = peg$parsehexDigit();
1263                  if (s2 !== peg$FAILED) {
1264                    s3 = peg$parsehexDigit();
1265                    if (s3 !== peg$FAILED) {
1266                      s4 = peg$parsehexDigit();
1267                      if (s4 !== peg$FAILED) {
1268                        s5 = peg$parsehexDigit();
1269                        if (s5 !== peg$FAILED) {
1270                          peg$reportedPos = s0;
1271                          s1 = peg$c59(s2, s3, s4, s5);
1272                          s0 = s1;
1273                        } else {
1274                          peg$currPos = s0;
1275                          s0 = peg$c2;
1276                        }
1277                      } else {
1278                        peg$currPos = s0;
1279                        s0 = peg$c2;
1280                      }
1281                    } else {
1282                      peg$currPos = s0;
1283                      s0 = peg$c2;
1284                    }
1285                  } else {
1286                    peg$currPos = s0;
1287                    s0 = peg$c2;
1288                  }
1289                } else {
1290                  peg$currPos = s0;
1291                  s0 = peg$c2;
1292                }
1293              }
1294            }
1295          }
1296        }
1297      }
1298
1299      return s0;
1300    }
1301
1302    function peg$parsedigits() {
1303      var s0, s1, s2;
1304
1305      s0 = peg$currPos;
1306      s1 = [];
1307      if (peg$c60.test(input.charAt(peg$currPos))) {
1308        s2 = input.charAt(peg$currPos);
1309        peg$currPos++;
1310      } else {
1311        s2 = peg$FAILED;
1312        if (peg$silentFails === 0) { peg$fail(peg$c61); }
1313      }
1314      if (s2 !== peg$FAILED) {
1315        while (s2 !== peg$FAILED) {
1316          s1.push(s2);
1317          if (peg$c60.test(input.charAt(peg$currPos))) {
1318            s2 = input.charAt(peg$currPos);
1319            peg$currPos++;
1320          } else {
1321            s2 = peg$FAILED;
1322            if (peg$silentFails === 0) { peg$fail(peg$c61); }
1323          }
1324        }
1325      } else {
1326        s1 = peg$c2;
1327      }
1328      if (s1 !== peg$FAILED) {
1329        peg$reportedPos = s0;
1330        s1 = peg$c62(s1);
1331      }
1332      s0 = s1;
1333
1334      return s0;
1335    }
1336
1337    function peg$parsehexDigit() {
1338      var s0;
1339
1340      if (peg$c63.test(input.charAt(peg$currPos))) {
1341        s0 = input.charAt(peg$currPos);
1342        peg$currPos++;
1343      } else {
1344        s0 = peg$FAILED;
1345        if (peg$silentFails === 0) { peg$fail(peg$c64); }
1346      }
1347
1348      return s0;
1349    }
1350
1351    function peg$parse_() {
1352      var s0, s1, s2;
1353
1354      peg$silentFails++;
1355      s0 = peg$currPos;
1356      s1 = [];
1357      s2 = peg$parsewhitespace();
1358      while (s2 !== peg$FAILED) {
1359        s1.push(s2);
1360        s2 = peg$parsewhitespace();
1361      }
1362      if (s1 !== peg$FAILED) {
1363        peg$reportedPos = s0;
1364        s1 = peg$c66(s1);
1365      }
1366      s0 = s1;
1367      peg$silentFails--;
1368      if (s0 === peg$FAILED) {
1369        s1 = peg$FAILED;
1370        if (peg$silentFails === 0) { peg$fail(peg$c65); }
1371      }
1372
1373      return s0;
1374    }
1375
1376    function peg$parsewhitespace() {
1377      var s0;
1378
1379      if (peg$c67.test(input.charAt(peg$currPos))) {
1380        s0 = input.charAt(peg$currPos);
1381        peg$currPos++;
1382      } else {
1383        s0 = peg$FAILED;
1384        if (peg$silentFails === 0) { peg$fail(peg$c68); }
1385      }
1386
1387      return s0;
1388    }
1389
1390    peg$result = peg$startRuleFunction();
1391
1392    if (peg$result !== peg$FAILED && peg$currPos === input.length) {
1393      return peg$result;
1394    } else {
1395      if (peg$result !== peg$FAILED && peg$currPos < input.length) {
1396        peg$fail({ type: "end", description: "end of input" });
1397      }
1398
1399      throw peg$buildException(null, peg$maxFailExpected, peg$maxFailPos);
1400    }
1401  }
1402
1403  return {
1404    SyntaxError: SyntaxError,
1405    parse:       parse
1406  };
1407})().parse;
1408
1409
1410/** @file messageformat.js - ICU PluralFormat + SelectFormat for JavaScript
1411 *  @author Alex Sexton - @SlexAxton
1412 *  @version 0.3.0-1
1413 *  @copyright 2012-2015 Alex Sexton, Eemeli Aro, and Contributors
1414 *  @license To use or fork, MIT. To contribute back, Dojo CLA  */
1415
1416
1417/** Utility function for quoting an Object's key value iff required
1418 *  @private  */
1419function propname(key, obj) {
1420  if (/^[A-Z_$][0-9A-Z_$]*$/i.test(key)) {
1421    return obj ? obj + '.' + key : key;
1422  } else {
1423    var jkey = JSON.stringify(key);
1424    return obj ? obj + '[' + jkey + ']' : jkey;
1425  }
1426};
1427
1428
1429/** Create a new message formatter
1430 *
1431 *  @class
1432 *  @global
1433 *  @param {string|string[]} [locale="en"] - The locale to use, with fallbacks
1434 *  @param {function} [pluralFunc] - Optional custom pluralization function
1435 *  @param {function[]} [formatters] - Optional custom formatting functions  */
1436function MessageFormat(locale, pluralFunc, formatters) {
1437  this.lc = [locale];  
1438  this.runtime.pluralFuncs = {};
1439  this.runtime.pluralFuncs[this.lc[0]] = pluralFunc;
1440  this.runtime.fmt = {};
1441  if (formatters) for (var f in formatters) {
1442    this.runtime.fmt[f] = formatters[f];
1443  }
1444}
1445
1446
1447
1448
1449/** Parse an input string to its AST
1450 *
1451 *  Precompiled from `lib/messageformat-parser.pegjs` by
1452 *  {@link http://pegjs.org/ PEG.js}. Included in MessageFormat object
1453 *  to enable testing.
1454 *
1455 *  @private  */
1456
1457
1458
1459/** Pluralization functions from
1460 *  {@link http://github.com/eemeli/make-plural.js make-plural}
1461 *
1462 *  @memberof MessageFormat
1463 *  @type Object.<string,function>  */
1464MessageFormat.plurals = {};
1465
1466
1467/** Default number formatting functions in the style of ICU's
1468 *  {@link http://icu-project.org/apiref/icu4j/com/ibm/icu/text/MessageFormat.html simpleArg syntax}
1469 *  implemented using the
1470 *  {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl Intl}
1471 *  object defined by ECMA-402.
1472 *
1473 *  **Note**: Intl is not defined in default Node until 0.11.15 / 0.12.0, so
1474 *  earlier versions require a {@link https://www.npmjs.com/package/intl pol
1474yfill}.
1475 *  Therefore {@link MessageFormat.withIntlSupport} needs to be true for these
1476 *  functions to be available for inclusion in the output.
1477 *
1478 *  @see MessageFormat#setIntlSupport
1479 *
1480 *  @namespace
1481 *  @memberof MessageFormat
1482 *  @property {function} number - Represent a number as an integer, percent or currency value
1483 *  @property {function} date - Represent a date as a full/long/default/short string
1484 *  @property {function} time - Represent a time as a full/long/default/short string
1485 *
1486 *  @example
1487 *  > var MessageFormat = require('messageformat');
1488 *  > var mf = (new MessageFormat('en')).setIntlSupport(true);
1489 *  > mf.currency = 'EUR';
1490 *  > var mfunc = mf.compile("The total is {V,number,currency}.");
1491 *  > mfunc({V:5.5})
1492 *  "The total is €5.50."
1493 *
1494 *  @example
1495 *  > var MessageFormat = require('messageformat');
1496 *  > var mf = new MessageFormat('en', null, {number: MessageFormat.number});
1497 *  > mf.currency = 'EUR';
1498 *  > var mfunc = mf.compile("The total is {V,number,currency}.");
1499 *  > mfunc({V:5.5})
1500 *  "The total is €5.50."  */
1501MessageFormat.formatters = {};
1502
1503/** Enable or disable support for the default formatters, which require the
1504 *  `Intl` object. Note that this can't be autodetected, as the environment
1505 *  in which the formatted text is compiled into Javascript functions is not
1506 *  necessarily the same environment in which they will get executed.
1507 *
1508 *  @see MessageFormat.formatters
1509 *
1510 *  @memberof MessageFormat
1511 *  @param {boolean} [enable=true]
1512 *  @returns {Object} The MessageFormat instance, to allow for chaining
1513 *  @example
1514 *  > var Intl = require('intl');
1515 *  > var MessageFormat = require('messageformat');
1516 *  > var mf = (new MessageFormat('en')).setIntlSupport(true);
1517 *  > mf.currency = 'EUR';
1518 *  > mf.compile("The total is {V,number,currency}.")({V:5.5});
1519 *  "The total is €5.50."  */
1520
1521
1522
1523/** A set of utility functions that are called by the compiled Javascript
1524 *  functions, these are included locally in the output of {@link
1525 *  MessageFormat#compile compile()}.
1526 *
1527 *  @namespace
1528 *  @memberof MessageFormat  */
1529MessageFormat.prototype.runtime = {
1530
1531  /** Utility function for `#` in plural rules
1532   *
1533   *  @param {number} value - The value to operate on
1534   *  @param {number} [offset=0] - An optional offset, set by the surrounding context  */
1535  number: function(value, offset) {
1536    if (isNaN(value)) throw new Error("'" + value + "' isn't a number.");
1537    return value - (offset || 0);
1538  },
1539
1540  /** Utility function for `{N, plural|selectordinal, ...}`
1541   *
1542   *  @param {number} value - The key to use to find a pluralization rule
1543   *  @param {number} offset - An offset to apply to `value`
1544   *  @param {function} lcfunc - A locale function from `pluralFuncs`
1545   *  @param {Object.<string,string>} data - The object from which results are looked up
1546   *  @param {?boolean} isOrdinal - If true, use ordinal rather than cardinal rules
1547   *  @returns {string} The result of the pluralization  */
1548  plural: function(value, offset, lcfunc, data, isOrdinal) {
1549    if ({}.hasOwnProperty.call(data, value)) return data[value]();
1550    if (offset) value -= offset;
1551    var key = lcfunc(value, isOrdinal);
1552    if (key in data) return data[key]();
1553    return data.other();
1554  },
1555
1556  /** Utility function for `{N, select, ...}`
1557   *
1558   *  @param {number} value - The key to use to find a selection
1559   *  @param {Object.<string,string>} data - The object from which results are looked up
1560   *  @returns {string} The result of the select statement  */
1561  select: function(value, data) {
1562    if ({}.hasOwnProperty.call(data, value)) return data[value]();
1563    return data.other()
1564  },
1565
1566  /** Pluralization functions included in compiled output
1567   *  @instance
1568   *  @type Object.<string,function>  */
1569  pluralFuncs: {},
1570
1571  /** Custom formatting functions called by `{var, fn[, args]*}` syntax
1572   *
1573   *  For examples, see {@link MessageFormat.formatters}
1574   *
1575   *  @instance
1576   *  @see MessageFormat.formatters
1577   *  @type Object.<string,function>  */
1578  fmt: {},
1579
1580  /** Custom stringifier to clean up browser inconsistencies
1581   *  @instance  */
1582  toString: function () {
1583    var _stringify = function(o, level) {
1584      if (typeof o != 'object') {
1585        var funcStr = o.toString().replace(/^(function )\w*/, '$1');
1586        var indent = /([ \t]*)\S.*$/.exec(funcStr);
1587        return indent ? funcStr.replace(new RegExp('^' + indent[1], 'mg'), '') : funcStr;
1588      }
1589      var s = [];
1590      for (var i in o) if (i != 'toString') {
1591        if (level == 0) s.push('var ' + i + ' = ' + _stringify(o[i], level 
vendor: 11,698 bytes, lines 1591-1909
1591+ 1) + ';\n');
1592        else s.push(propname(i) + ': ' + _stringify(o[i], level + 1));
1593      }
1594      if (level == 0) return s.join('');
1595      if (s.length == 0) return '{}';
1596      var indent = '  '; while (--level) indent += '  ';
1597      return '{\n' + s.join(',\n').replace(/^/gm, indent) + '\n}';
1598    };
1599    return _stringify(this, 0);
1600  }
1601};
1602
1603
1604/** Recursively map an AST to its resulting string
1605 *
1606 *  @memberof MessageFormat
1607 *
1608 *  @param ast - the Ast node for which the JS code should be generated
1609 *
1610 *  @private  */
1611MessageFormat.prototype._precompile = function(ast, data) {
1612  data = data || { keys: {}, offset: {} };
1613  var r = [], i, tmp, args = [];
1614
1615  switch ( ast.type ) {
1616    case 'messageFormatPattern':
1617      for ( i = 0; i < ast.statements.length; ++i ) {
1618        r.push(this._precompile( ast.statements[i], data ));
1619      }
1620      tmp = r.join(' + ') || '""';
1621      return data.pf_count ? tmp : 'function(d) { return ' + tmp + '; }';
1622
1623    case 'messageFormatElement':
1624      data.pf_count = data.pf_count || 0;
1625      if ( ast.output ) {
1626        return propname(ast.argumentIndex, 'd');
1627      }
1628      else {
1629        data.keys[data.pf_count] = ast.argumentIndex;
1630        return this._precompile( ast.elementFormat, data );
1631      }
1632      return '';
1633
1634    case 'elementFormat':
1635      args = [ propname(data.keys[data.pf_count], 'd') ];
1636      switch (ast.key) {
1637        case 'select':
1638          args.push(this._precompile(ast.val, data));
1639          return 'select(' + args.join(', ') + ')';
1640        case 'selectordinal':
1641          args = args.concat([ 0, propname(this.lc[0], 'pluralFuncs'), this._precompile(ast.val, data), 1 ]);
1642          return 'plural(' + args.join(', ') + ')';
1643        case 'plural':
1644          data.offset[data.pf_count || 0] = ast.val.offset || 0;
1645          args = args.concat([ data.offset[data.pf_count] || 0, propname(this.lc[0], 'pluralFuncs'), this._precompile(ast.val, data) ]);
1646          return 'plural(' + args.join(', ') + ')';
1647        default:
1648          if (this.withIntlSupport && !(ast.key in this.runtime.fmt) && (ast.key in MessageFormat.formatters)) {
1649            tmp = MessageFormat.formatters[ast.key];
1650            this.runtime.fmt[ast.key] = (typeof tmp(this) == 'function') ? tmp(this) : tmp;
1651          }
1652          args.push(JSON.stringify(this.lc));
1653          if (ast.val && ast.val.length) args.push(JSON.stringify(ast.val.length == 1 ? ast.val[0] : ast.val));
1654          return 'fmt.' + ast.key + '(' + args.join(', ') + ')';
1655      }
1656
1657    case 'pluralFormatPattern':
1658    case 'selectFormatPattern':
1659      data.pf_count = data.pf_count || 0;
1660      if (ast.type == 'selectFormatPattern') data.offset[data.pf_count] = 0;
1661      var needOther = true;
1662      for (i = 0; i < ast.pluralForms.length; ++i) {
1663        var key = ast.pluralForms[i].key;
1664        if (key === 'other') needOther = false;
1665        var data_copy = JSON.parse(JSON.stringify(data));
1666        data_copy.pf_count++;
1667        r.push(propname(key) + ': function() { return ' + this._precompile(ast.pluralForms[i].val, data_copy) + ';}');
1668      }
1669      if (needOther) throw new Error("No 'other' form found in " + ast.type + " " + data.pf_count);
1670      return '{ ' + r.join(', ') + ' }';
1671
1672    case 'string':
1673      return JSON.stringify(ast.val || "");
1674
1675    case 'octothorpe':
1676      if (!data.pf_count) return '"#"';
1677      args = [ propname(data.keys[data.pf_count-1], 'd') ];
1678      if (data.offset[data.pf_count-1]) args.push(data.offset[data.pf_count-1]);
1679      return 'number(' + args.join(', ') + ')';
1680
1681    default:
1682      throw new Error( 'Bad AST type: ' + ast.type );
1683  }
1684};
1685
1686/** Compile messages into an executable function with clean string
1687 *  representation.
1688 *
1689 *  If `messages` is a single string including ICU MessageFormat declarations,
1690 *  `opt` is ignored and the returned function takes a single Object parameter
1691 *  `d` representing each of the input's defined variables. The returned
1692 *  function will be defined in a local scope that includes all the required
1693 *  runtime variables.
1694 *
1695 *  If `messages` is a map of keys to strings, or a map of namespace keys to
1696 *  such key/string maps, the returned function will fill the specified global
1697 *  with javascript functions matching the structure of the input. In such use,
1698 *  the output of `compile()` is expected to be serialized using `.toString()`,
1699 *  and will include definitions of the runtime functions. If `opt.global` is
1700 *  null, calling the output function will return the object itself.
1701 *
1702 *  Together, the input parameters should match the following patterns:
1703 *  ```js
1704 *  messages = "string" || { key0: "string0", key1: "string1", ... } || {
1705 *    ns0: { key0: "string0", key1: "string1", ...  },
1706 *    ns1: { key0: "string0", key1: "string1", ...  },
1707 *    ...
1708 *  }
1709 *
1710 *  opt = null || {
1711 *    locale: null || {
1712 *      ns0: "lc0" || [ "lc0", ... ],
1713 *      ns1: "lc1" || [ "lc1", ... ],
1714 *      ...
1715 *    },
1716 *    global: null || "module.exports" || "exports" || "i18n" || ...
1717 *  }
1718 *  ```
1719 *
1720 *  @memberof MessageFormat
1721 *  @param {string|Object}
1722 *      messages - The input message(s) to be compiled, in ICU MessageFormat
1723 *  @param {Object} [opt={}] - Options controlling output for non-simple intput
1724 *  @param {Object} [opt.locale] - The locales to use for the messages, with a
1725 *      structure matching that of `messages`
1726 *  @param {string} [opt.global=""] - The global variable that the output
1727 *      function should use, or a null string for none. "exports" and
1728 *      "module.exports" are recognised as special cases.
1729 *  @returns {function} The first match found for the given locale(s)
1730 *
1731 *  @example
1732 * > var MessageFormat = require('messageformat'),
1733 * ...   mf = new MessageFormat('en'),
1734 * ...   mfunc0 = mf.compile('A {TYPE} example.');
1735 * > mfunc0({TYPE:'simple'})
1736 * 'A simple example.'
1737 * > mfunc0.toString()
1738 * 'function (d) { return "A " + d.TYPE + " example."; }'
1739 *
1740 *  @example
1741 * > var msgSet = { a: 'A {TYPE} example.',
1742 * ...              b: 'This has {COUNT, plural, one{one member} other{# members}}.' },
1743 * ...   mfuncSet = mf.compile(msgSet);
1744 * > mfuncSet().a({TYPE:'more complex'})
1745 * 'A more complex example.'
1746 * > mfuncSet().b({COUNT:2})
1747 * 'This has 2 members.'
1748 *
1749 * > console.log(mfuncSet.toString())
1750 * function anonymous() {
1751 * var number = function (value, offset) {
1752 *   if (isNaN(value)) throw new Error("'" + value + "' isn't a number.");
1753 *   return value - (offset || 0);
1754 * };
1755 * var plural = function (value, offset, lcfunc, data, isOrdinal) {
1756 *   if ({}.hasOwnProperty.call(data, value)) return data[value]();
1757 *   if (offset) value -= offset;
1758 *   var key = lcfunc(value, isOrdinal);
1759 *   if (key in data) return data[key]();
1760 *   return data.other();
1761 * };
1762 * var select = function (value, data) {
1763 *   if ({}.hasOwnProperty.call(data, value)) return data[value]();
1764 *   return data.other()
1765 * };
1766 * var pluralFuncs = {
1767 *   en: function (n, ord) {
1768 *     var s = String(n).split('.'), v0 = !s[1], t0 = Number(s[0]) == n,
1769 *         n10 = t0 && s[0].slice(-1), n100 = t0 && s[0].slice(-2);
1770 *     if (ord) return (n10 == 1 && n100 != 11) ? 'one'
1771 *         : (n10 == 2 && n100 != 12) ? 'two'
1772 *         : (n10 == 3 && n100 != 13) ? 'few'
1773 *         : 'other';
1774 *     return (n == 1 && v0) ? 'one' : 'other';
1775 *   }
1776 * };
1777 * var fmt = {};
1778 *
1779 * return {
1780 *   a: function(d) { return "A " + d.TYPE + " example."; },
1781 *   b: function(d) { return "This has " + plural(d.COUNT, 0, pluralFuncs.en, { one: function() { return "one member";}, other: function() { return number(d.COUNT)+" members";} }) + "."; }
1782 * }
1783 * }
1784 *
1785 *  @example
1786 * > mf.runtime.pluralFuncs.fi = MessageFormat.plurals.fi;
1787 * > var multiSet = { en: { a: 'A {TYPE} example.',
1788 * ...                      b: 'This is the {COUNT, selectordinal, one{#st} two{#nd} few{#rd} other{#th}} example.' },
1789 * ...                fi: { a: '{TYPE} esimerkki.',
1790 * ...                      b: 'Tämä on {COUNT, selectordinal, other{#.}} esimerkki.' } },
1791 * ...   multiSetLocales = { en: 'en', fi: 'fi' },
1792 * ...   mfuncSet = mf.compile(multiSet, { locale: multiSetLocales, global: 'i18n' });
1793 * > mfuncSet(this);
1794 * > i18n.en.b({COUNT:3})
1795 * 'This is the 3rd example.'
1796 * > i18n.fi.b({COUNT:3})
1797 * 'Tämä on 3. esimerkki.'  */
1798MessageFormat.prototype.compile = function ( messages, opt ) {
1799  var r = {}, lc0 = this.lc,
1800      compileMsg = function(self, msg) {
1801        try {
1802          var ast = MessageFormat._parse(msg);
1803          return self._precompile(ast);
1804        } catch (e) {
1805          throw new Error((ast ? 'Precompiler' : 'Parser') + ' error: ' + e.toString());
1806        }
1807      },
1808      stringify = function(r, level) {
1809        if (!level) level = 0;
1810        if (typeof r != 'object') return r;
1811        var o = [], indent = '';
1812        for (var i = 0; i < level; ++i) indent += '  ';
1813        for (var k in r) o.push('\n' + indent + '  ' + propname(k) + ': ' + stringify(r[k], level + 1));
1814        return '{' + o.join(',') + '\n' + indent + '}';
1815      };
1816
1817  if (typeof messages == 'string') {
1818    var f = new Function(
1819        'number, plural, select, pluralFuncs, fmt',
1820        'return ' + compileMsg(this, messages));
1821    return f(this.runtime.number, this.runtime.plural, this.runtime.select,
1822        this.runtime.pluralFuncs, this.runtime.fmt);
1823  }
1824
1825  opt = opt || {};
1826
1827  for (var ns in messages) {
1828    if (opt.locale) this.lc = opt.locale[ns] && [].concat(opt.locale[ns]) || lc0;
1829    if (typeof messages[ns] == 'string') {
1830      try { r[ns] = compileMsg(this, messages[ns]); }
1831      catch (e) { e.message = e.message.replace(':', ' with `' + ns + '`:'); throw e; }
1832    } else {
1833      r[ns] = {};
1834      for (var key in messages[ns]) {
1835        try { r[ns][key] = compileMsg(this, messages[ns][key]); }
1836        catch (e) { e.message = e.message.replace(':', ' with `' + key + '` in `' + ns + '`:'); throw e; }
1837      }
1838    }
1839  }
1840
1841  this.lc = lc0;
1842  var s = this.runtime.toString() + '\n';
1843  switch (opt.global || '') {
1844    case 'exports':
1845      var o = [];
1846      for (var k in r) o.push(propname(k, 'exports') + ' = ' + stringify(r[k]));
1847      return new Function(s + o.join(';\n'));
1848    case 'module.exports':
1849      return new Function(s + 'module.exports = ' + stringify(r));
1850    case '':
1851      return new Function(s + 'return ' + stringify(r));
1852    default:
1853      return new Function('G', s + propname(opt.global, 'G') + ' = ' + stringify(r));
1854  }
1855};
1856
1857
1858return MessageFormat;
1859}());
1860/* jshint ignore:end */
1861
1862
1863var validateMessageBundle = function( cldr ) {
1864	validate(
1865		"E_MISSING_MESSAGE_BUNDLE",
1866		"Missing message bundle for locale `{locale}`.",
1867		cldr.attributes.bundle && cldr.get( "globalize-messages/{bundle}" ) !== undefined,
1868		{
1869			locale: cldr.locale
1870		}
1871	);
1872};
1873
1874
1875
1876
1877var validateMessagePresence = function( path, value ) {
1878	path = path.join( "/" );
1879	validate( "E_MISSING_MESSAGE", "Missing required message content `{path}`.",
1880		value !== undefined, { path: path } );
1881};
1882
1883
1884
1885
1886var validateMessageType = function( path, value ) {
1887	path = path.join( "/" );
1888	validate(
1889		"E_INVALID_MESSAGE",
1890		"Invalid message content `{path}`. {expected} expected.",
1891		typeof value === "string",
1892		{
1893			expected: "a string",
1894			path: path
1895		}
1896	);
1897};
1898
1899
1900
1901
1902var validateParameterTypeMessageVariables = function( value, name ) {
1903	validateParameterType(
1904		value,
1905		name,
1906		value === undefined || isPlainObject( value ) || Array.isArray( value ),
1907		"Array or Plain Object"
1908	);
1909};
1910
1911
1912
1913
1914var validatePluralModulePresence = function() {
1915	validate( "E_MISSING_PLURAL_MODULE", "Plural module not loaded.",
1916		Globalize.plural !== undefined, {} );
1917};
1918
1919
1920
1921
1922var slice = [].slice;
1923
1924function MessageFormatInit( globalize, cldr ) {
1925	var plural;
1926	return new MessageFormat( cldr.locale, function( value ) {
1927		if ( !plural ) {
1928			validatePluralModulePresence();
1929			plural = globalize.pluralGenerator();
1930		}
1931		return plural( value );
1932	});
1933}
1934
1935/**
1936 * .loadMessages( json )
1937 *
1938 * @json [JSON]
1939 *
1940 * Load translation data.
1941 */
1942Globalize.loadMessages = function( json ) {
1943	var locale,
1944		customData = {
1945			"globalize-messages": json,
1946			"main": {}
1947		};
1948
1949	validateParameterPresence( json, "json" );
1950	validateParameterTypePlainObject( json, "json" );
1951
1952	// Set available bundles by populating customData main dataset.
1953	for ( locale in json ) {
1954		if ( json.hasOwnProperty( locale ) ) {
1955			customData.main[ locale ] = {};
1956		}
1957	}
1958
1959	Cldr.load( customData );
1960};
1961
1962/**
1963 * .messageFormatter( path )
1964 *
1965 * @path [String or Array]
1966 *
1967 * Format a message given its path.
1968 */
1969Globalize.messageFormatter =
1970Globalize.prototype.messageFormatter = function( path ) {
1971	var cldr, formatter, message;
1972
1973	validateParameterPresence( path, "path" );
1974	validateParameterType( path, "path", typeof path === "string" || Array.isArray( path ),
1975		"a String nor an Array" );
1976
1977	path = alwaysArray( path );
1978	cldr = this.cldr;
1979
1980	validateDefaultLocale( cldr );
1981	validateMessageBundle( cldr );
1982
1983	message = cldr.get( [ "globalize-messages/{bundle}" ].concat( path ) );
1984	validateMessagePresence( path, message );
1985
1986	// If message is an Array, concatenate it.
1987	if ( Array.isArray( message ) ) {
1988		message = message.join( " " );
1989	}
1990	validateMessageType( path, message );
1991
1992	formatter = MessageFormatInit( this, cldr ).compile( message );
1993
1994	return function( variables ) {
1995		if ( typeof variables === "number" || typeof variables === "string" ) {
1996			variables = slice.call( arguments, 0 );
1997		}
1998		validateParameterTypeMessageVariables( variables, "variables" );
1999		return formatter( variables );
2000	};
2001};
2002
2003/**
2004 * .formatMessage( path [, variables] )
2005 *
2006 * @path [String or Array]
2007 *
2008 * @variables [Number, String, Array or Object]
2009 *
2010 * Format a message given its path.
2011 */
2012Globalize.formatMessage =
2013Globalize.prototype.formatMessage = function( path /* , variables */ ) {
2014	return this.messageFormatter( path ).apply( {}, slice.call( arguments, 1 ) );
2015};
2016
2017return Globalize;
2018
2019
2020
2021
2022}));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.