globalize-rpk 1.7.0 → 1.7.1

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