globalize.message.js 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846
  1. /**
  2. * Globalize v1.0.1
  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: 2016-01-20T16:57Z
  11. */
  12. /*!
  13. * Globalize v1.0.1 2016-01-20T16:57Z Released under the MIT license
  14. * http://git.io/TrdQbw
  15. */
  16. (function( root, factory ) {
  17. // UMD returnExports
  18. if ( typeof define === "function" && define.amd ) {
  19. // AMD
  20. define([
  21. "cldr",
  22. "../globalize",
  23. "cldr/event"
  24. ], factory );
  25. } else if ( typeof exports === "object" ) {
  26. // Node, CommonJS
  27. module.exports = factory( require( "cldrjs" ), require( "globalize" ) );
  28. } else {
  29. // Extend global
  30. factory( root.Cldr, root.Globalize );
  31. }
  32. }(this, function( Cldr, Globalize ) {
  33. var alwaysArray = Globalize._alwaysArray,
  34. isPlainObject = Globalize._isPlainObject,
  35. validate = Globalize._validate,
  36. validateDefaultLocale = Globalize._validateDefaultLocale,
  37. validateParameterPresence = Globalize._validateParameterPresence,
  38. validateParameterType = Globalize._validateParameterType,
  39. validateParameterTypePlainObject = Globalize._validateParameterTypePlainObject;
  40. /**
  41. * messageformat.js
  42. *
  43. * ICU PluralFormat + SelectFormat for JavaScript
  44. *
  45. * Copyright 2014
  46. *
  47. * Licensed under the MIT License
  48. *
  49. * @author Alex Sexton - @SlexAxton
  50. * @version 0.2.1
  51. * @contributor_license Dojo CLA
  52. */
  53. var MessageFormat;
  54. /* jshint ignore:start */
  55. MessageFormat = (function() {
  56. function MessageFormat(locale, pluralFunc, formatters) {
  57. if (!locale) {
  58. this.lc = ['en'];
  59. } else if (typeof locale == 'string') {
  60. this.lc = [];
  61. for (var l = locale; l; l = l.replace(/[-_]?[^-_]*$/, '')) this.lc.push(l);
  62. } else {
  63. this.lc = locale;
  64. }
  65. this.runtime.pf = {};
  66. this.runtime.pf[this.lc[0]] = pluralFunc;
  67. this.runtime.fmt = {};
  68. if (formatters) for (var f in formatters) {
  69. this.runtime.fmt[f] = formatters[f];
  70. }
  71. }
  72. if (!('plurals' in MessageFormat)) MessageFormat.plurals = {};
  73. // note: Intl is not defined in default Node until joyent/node#7676 lands
  74. MessageFormat.formatters = {
  75. number: function(self) {
  76. return new Function("v,lc,p",
  77. "return Intl.NumberFormat(lc,\n" +
  78. " p=='integer' ? {maximumFractionDigits:0}\n" +
  79. " : p=='percent' ? {style:'percent'}\n" +
  80. " : p=='currency' ? {style:'currency', currency:'" + (self.currency || 'USD') + "', minimumFractionDigits:2, maximumFractionDigits:2}\n" +
  81. " : {}).format(v)"
  82. );
  83. },
  84. date: function(v,lc,p) {
  85. var o = {day:'numeric', month:'short', year:'numeric'};
  86. switch (p) {
  87. case 'full': o.weekday = 'long';
  88. case 'long': o.month = 'long'; break;
  89. case 'short': o.month = 'numeric';
  90. }
  91. return (new Date(v)).toLocaleDateString(lc, o)
  92. },
  93. time: function(v,lc,p) {
  94. var o = {second:'numeric', minute:'numeric', hour:'numeric'};
  95. switch (p) {
  96. case 'full': case 'long': o.timeZoneName = 'short'; break;
  97. case 'short': delete o.minute;
  98. }
  99. return (new Date(v)).toLocaleTimeString(lc, o)
  100. }
  101. };
  102. MessageFormat.prototype.setIntlSupport = function(enable) {
  103. this.withIntlSupport = !!enable || (typeof enable == 'undefined');
  104. return this;
  105. };
  106. MessageFormat.prototype.runtime = {
  107. _n: function(v,o){if(isNaN(v))throw new Error("'"+v+"' isn't a number.");return v-(o||0)},
  108. _p: function(v,o,l,p,s){return v in p?p[v]:(v=l(v-o,s),v in p?p[v]:p.other)},
  109. _s: function(v,p){return v in p?p[v]:p.other},
  110. pf: {},
  111. fmt: {},
  112. toString: function () {
  113. var _stringify = function(o, top) {
  114. if (typeof o != 'object') return o.toString().replace(/^(function) \w*/, '$1');
  115. var s = [];
  116. for (var i in o) if (i != 'toString') {
  117. s.push((top ? i + '=' : JSON.stringify(i) + ':') + _stringify(o[i], false));
  118. }
  119. return top ? s.join(',\n') : '{' + s.join(',\n') + '}';
  120. };
  121. return _stringify(this, true);
  122. }
  123. };
  124. // This is generated and pulled in for browsers.
  125. var mparser = (function() {
  126. /*
  127. * Generated by PEG.js 0.8.0.
  128. *
  129. * http://pegjs.majda.cz/
  130. */
  131. function peg$subclass(child, parent) {
  132. function ctor() { this.constructor = child; }
  133. ctor.prototype = parent.prototype;
  134. child.prototype = new ctor();
  135. }
  136. function SyntaxError(message, expected, found, offset, line, column) {
  137. this.message = message;
  138. this.expected = expected;
  139. this.found = found;
  140. this.offset = offset;
  141. this.line = line;
  142. this.column = column;
  143. this.name = "SyntaxError";
  144. }
  145. peg$subclass(SyntaxError, Error);
  146. function parse(input) {
  147. var options = arguments.length > 1 ? arguments[1] : {},
  148. peg$FAILED = {},
  149. peg$startRuleFunctions = { start: peg$parsestart },
  150. peg$startRuleFunction = peg$parsestart,
  151. peg$c0 = function(messageFormatPattern) { return { type: "program", program: messageFormatPattern }; },
  152. peg$c1 = peg$FAILED,
  153. peg$c2 = [],
  154. peg$c3 = function(s1, inner) {
  155. var st = [];
  156. if ( s1 && s1.val ) {
  157. st.push( s1 );
  158. }
  159. for( var i in inner ){
  160. if ( inner.hasOwnProperty( i ) ) {
  161. st.push( inner[ i ] );
  162. }
  163. }
  164. return { type: 'messageFormatPattern', statements: st };
  165. },
  166. peg$c4 = "{",
  167. peg$c5 = { type: "literal", value: "{", description: "\"{\"" },
  168. peg$c6 = "}",
  169. peg$c7 = { type: "literal", value: "}", description: "\"}\"" },
  170. peg$c8 = function(mfe, s1) {
  171. var res = [];
  172. if ( mfe ) {
  173. res.push(mfe);
  174. }
  175. if ( s1 && s1.val ) {
  176. res.push( s1 );
  177. }
  178. return { type: "messageFormatPatternRight", statements : res };
  179. },
  180. peg$c9 = null,
  181. peg$c10 = ",",
  182. peg$c11 = { type: "literal", value: ",", description: "\",\"" },
  183. peg$c12 = function(argIdx, efmt) {
  184. var res = {
  185. type: "messageFormatElement",
  186. argumentIndex: argIdx
  187. };
  188. if ( efmt && efmt.length ) {
  189. res.elementFormat = efmt[1];
  190. }
  191. else {
  192. res.output = true;
  193. }
  194. return res;
  195. },
  196. peg$c13 = "plural",
  197. peg$c14 = { type: "literal", value: "plural", description: "\"plural\"" },
  198. peg$c15 = function(t, s) {
  199. return {
  200. type : "elementFormat",
  201. key : t,
  202. val : s.val
  203. };
  204. },
  205. peg$c16 = "selectordinal",
  206. peg$c17 = { type: "literal", value: "selectordinal", description: "\"selectordinal\"" },
  207. peg$c18 = "select",
  208. peg$c19 = { type: "literal", value: "select", description: "\"select\"" },
  209. peg$c20 = function(t, p) {
  210. return {
  211. type : "elementFormat",
  212. key : t,
  213. val : p
  214. };
  215. },
  216. peg$c21 = function(pfp) {
  217. return { type: "pluralStyle", val: pfp };
  218. },
  219. peg$c22 = function(sfp) {
  220. return { type: "selectStyle", val: sfp };
  221. },
  222. peg$c23 = function(op, pf) {
  223. var res = {
  224. type: "pluralFormatPattern",
  225. pluralForms: pf
  226. };
  227. if ( op ) {
  228. res.offset = op;
  229. }
  230. else {
  231. res.offset = 0;
  232. }
  233. return res;
  234. },
  235. peg$c24 = "offset",
  236. peg$c25 = { type: "literal", value: "offset", description: "\"offset\"" },
  237. peg$c26 = ":",
  238. peg$c27 = { type: "literal", value: ":", description: "\":\"" },
  239. peg$c28 = function(d) {
  240. return d;
  241. },
  242. peg$c29 = function(pf) {
  243. return {
  244. type: "selectFormatPattern",
  245. pluralForms: pf
  246. };
  247. },
  248. peg$c30 = function(k, mfp) {
  249. return {
  250. type: "pluralForms",
  251. key: k,
  252. val: mfp
  253. };
  254. },
  255. peg$c31 = function(i) {
  256. return i;
  257. },
  258. peg$c32 = "=",
  259. peg$c33 = { type: "literal", value: "=", description: "\"=\"" },
  260. peg$c34 = function(p) {
  261. return p;
  262. },
  263. peg$c35 = function(ws, s) {
  264. var tmp = [];
  265. for( var i = 0; i < s.length; ++i ) {
  266. for( var j = 0; j < s[ i ].length; ++j ) {
  267. tmp.push(s[i][j]);
  268. }
  269. }
  270. return {
  271. type: "string",
  272. val: ws + tmp.join('')
  273. };
  274. },
  275. peg$c36 = /^[0-9a-zA-Z$_]/,
  276. peg$c37 = { type: "class", value: "[0-9a-zA-Z$_]", description: "[0-9a-zA-Z$_]" },
  277. peg$c38 = /^[^ \t\n\r,.+={}]/,
  278. peg$c39 = { type: "class", value: "[^ \\t\\n\\r,.+={}]", description: "[^ \\t\\n\\r,.+={}]" },
  279. peg$c40 = function(s1, s2) {
  280. return s1 + (s2 ? s2.join('') : '');
  281. },
  282. peg$c41 = function(chars) { return chars.join(''); },
  283. peg$c42 = /^[^{}\\\0-\x1F \t\n\r]/,
  284. peg$c43 = { type: "class", value: "[^{}\\\\\\0-\\x1F \\t\\n\\r]", description: "[^{}\\\\\\0-\\x1F \\t\\n\\r]" },
  285. peg$c44 = function(x) {
  286. return x;
  287. },
  288. peg$c45 = "\\#",
  289. peg$c46 = { type: "literal", value: "\\#", description: "\"\\\\#\"" },
  290. peg$c47 = function() {
  291. return "\\#";
  292. },
  293. peg$c48 = "\\{",
  294. peg$c49 = { type: "literal", value: "\\{", description: "\"\\\\{\"" },
  295. peg$c50 = function() {
  296. return "\u007B";
  297. },
  298. peg$c51 = "\\}",
  299. peg$c52 = { type: "literal", value: "\\}", description: "\"\\\\}\"" },
  300. peg$c53 = function() {
  301. return "\u007D";
  302. },
  303. peg$c54 = "\\u",
  304. peg$c55 = { type: "literal", value: "\\u", description: "\"\\\\u\"" },
  305. peg$c56 = function(h1, h2, h3, h4) {
  306. return String.fromCharCode(parseInt("0x" + h1 + h2 + h3 + h4));
  307. },
  308. peg$c57 = /^[0-9]/,
  309. peg$c58 = { type: "class", value: "[0-9]", description: "[0-9]" },
  310. peg$c59 = function(ds) {
  311. return parseInt((ds.join('')), 10);
  312. },
  313. peg$c60 = /^[0-9a-fA-F]/,
  314. peg$c61 = { type: "class", value: "[0-9a-fA-F]", description: "[0-9a-fA-F]" },
  315. peg$c62 = { type: "other", description: "whitespace" },
  316. peg$c63 = function(w) { return w.join(''); },
  317. peg$c64 = /^[ \t\n\r]/,
  318. peg$c65 = { type: "class", value: "[ \\t\\n\\r]", description: "[ \\t\\n\\r]" },
  319. peg$currPos = 0,
  320. peg$reportedPos = 0,
  321. peg$cachedPos = 0,
  322. peg$cachedPosDetails = { line: 1, column: 1, seenCR: false },
  323. peg$maxFailPos = 0,
  324. peg$maxFailExpected = [],
  325. peg$silentFails = 0,
  326. peg$result;
  327. if ("startRule" in options) {
  328. if (!(options.startRule in peg$startRuleFunctions)) {
  329. throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
  330. }
  331. peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
  332. }
  333. function text() {
  334. return input.substring(peg$reportedPos, peg$currPos);
  335. }
  336. function offset() {
  337. return peg$reportedPos;
  338. }
  339. function line() {
  340. return peg$computePosDetails(peg$reportedPos).line;
  341. }
  342. function column() {
  343. return peg$computePosDetails(peg$reportedPos).column;
  344. }
  345. function expected(description) {
  346. throw peg$buildException(
  347. null,
  348. [{ type: "other", description: description }],
  349. peg$reportedPos
  350. );
  351. }
  352. function error(message) {
  353. throw peg$buildException(message, null, peg$reportedPos);
  354. }
  355. function peg$computePosDetails(pos) {
  356. function advance(details, startPos, endPos) {
  357. var p, ch;
  358. for (p = startPos; p < endPos; p++) {
  359. ch = input.charAt(p);
  360. if (ch === "\n") {
  361. if (!details.seenCR) { details.line++; }
  362. details.column = 1;
  363. details.seenCR = false;
  364. } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") {
  365. details.line++;
  366. details.column = 1;
  367. details.seenCR = true;
  368. } else {
  369. details.column++;
  370. details.seenCR = false;
  371. }
  372. }
  373. }
  374. if (peg$cachedPos !== pos) {
  375. if (peg$cachedPos > pos) {
  376. peg$cachedPos = 0;
  377. peg$cachedPosDetails = { line: 1, column: 1, seenCR: false };
  378. }
  379. advance(peg$cachedPosDetails, peg$cachedPos, pos);
  380. peg$cachedPos = pos;
  381. }
  382. return peg$cachedPosDetails;
  383. }
  384. function peg$fail(expected) {
  385. if (peg$currPos < peg$maxFailPos) { return; }
  386. if (peg$currPos > peg$maxFailPos) {
  387. peg$maxFailPos = peg$currPos;
  388. peg$maxFailExpected = [];
  389. }
  390. peg$maxFailExpected.push(expected);
  391. }
  392. function peg$buildException(message, expected, pos) {
  393. function cleanupExpected(expected) {
  394. var i = 1;
  395. expected.sort(function(a, b) {
  396. if (a.description < b.description) {
  397. return -1;
  398. } else if (a.description > b.description) {
  399. return 1;
  400. } else {
  401. return 0;
  402. }
  403. });
  404. while (i < expected.length) {
  405. if (expected[i - 1] === expected[i]) {
  406. expected.splice(i, 1);
  407. } else {
  408. i++;
  409. }
  410. }
  411. }
  412. function buildMessage(expected, found) {
  413. function stringEscape(s) {
  414. function hex(ch) { return ch.charCodeAt(0).toString(16).toUpperCase(); }
  415. return s
  416. .replace(/\\/g, '\\\\')
  417. .replace(/"/g, '\\"')
  418. .replace(/\x08/g, '\\b')
  419. .replace(/\t/g, '\\t')
  420. .replace(/\n/g, '\\n')
  421. .replace(/\f/g, '\\f')
  422. .replace(/\r/g, '\\r')
  423. .replace(/[\x00-\x07\x0B\x0E\x0F]/g, function(ch) { return '\\x0' + hex(ch); })
  424. .replace(/[\x10-\x1F\x80-\xFF]/g, function(ch) { return '\\x' + hex(ch); })
  425. .replace(/[\u0180-\u0FFF]/g, function(ch) { return '\\u0' + hex(ch); })
  426. .replace(/[\u1080-\uFFFF]/g, function(ch) { return '\\u' + hex(ch); });
  427. }
  428. var expectedDescs = new Array(expected.length),
  429. expectedDesc, foundDesc, i;
  430. for (i = 0; i < expected.length; i++) {
  431. expectedDescs[i] = expected[i].description;
  432. }
  433. expectedDesc = expected.length > 1
  434. ? expectedDescs.slice(0, -1).join(", ")
  435. + " or "
  436. + expectedDescs[expected.length - 1]
  437. : expectedDescs[0];
  438. foundDesc = found ? "\"" + stringEscape(found) + "\"" : "end of input";
  439. return "Expected " + expectedDesc + " but " + foundDesc + " found.";
  440. }
  441. var posDetails = peg$computePosDetails(pos),
  442. found = pos < input.length ? input.charAt(pos) : null;
  443. if (expected !== null) {
  444. cleanupExpected(expected);
  445. }
  446. return new SyntaxError(
  447. message !== null ? message : buildMessage(expected, found),
  448. expected,
  449. found,
  450. pos,
  451. posDetails.line,
  452. posDetails.column
  453. );
  454. }
  455. function peg$parsestart() {
  456. var s0, s1;
  457. s0 = peg$currPos;
  458. s1 = peg$parsemessageFormatPattern();
  459. if (s1 !== peg$FAILED) {
  460. peg$reportedPos = s0;
  461. s1 = peg$c0(s1);
  462. }
  463. s0 = s1;
  464. return s0;
  465. }
  466. function peg$parsemessageFormatPattern() {
  467. var s0, s1, s2, s3;
  468. s0 = peg$currPos;
  469. s1 = peg$parsestring();
  470. if (s1 !== peg$FAILED) {
  471. s2 = [];
  472. s3 = peg$parsemessageFormatPatternRight();
  473. while (s3 !== peg$FAILED) {
  474. s2.push(s3);
  475. s3 = peg$parsemessageFormatPatternRight();
  476. }
  477. if (s2 !== peg$FAILED) {
  478. peg$reportedPos = s0;
  479. s1 = peg$c3(s1, s2);
  480. s0 = s1;
  481. } else {
  482. peg$currPos = s0;
  483. s0 = peg$c1;
  484. }
  485. } else {
  486. peg$currPos = s0;
  487. s0 = peg$c1;
  488. }
  489. return s0;
  490. }
  491. function peg$parsemessageFormatPatternRight() {
  492. var s0, s1, s2, s3, s4, s5, s6;
  493. s0 = peg$currPos;
  494. if (input.charCodeAt(peg$currPos) === 123) {
  495. s1 = peg$c4;
  496. peg$currPos++;
  497. } else {
  498. s1 = peg$FAILED;
  499. if (peg$silentFails === 0) { peg$fail(peg$c5); }
  500. }
  501. if (s1 !== peg$FAILED) {
  502. s2 = peg$parse_();
  503. if (s2 !== peg$FAILED) {
  504. s3 = peg$parsemessageFormatElement();
  505. if (s3 !== peg$FAILED) {
  506. s4 = peg$parse_();
  507. if (s4 !== peg$FAILED) {
  508. if (input.charCodeAt(peg$currPos) === 125) {
  509. s5 = peg$c6;
  510. peg$currPos++;
  511. } else {
  512. s5 = peg$FAILED;
  513. if (peg$silentFails === 0) { peg$fail(peg$c7); }
  514. }
  515. if (s5 !== peg$FAILED) {
  516. s6 = peg$parsestring();
  517. if (s6 !== peg$FAILED) {
  518. peg$reportedPos = s0;
  519. s1 = peg$c8(s3, s6);
  520. s0 = s1;
  521. } else {
  522. peg$currPos = s0;
  523. s0 = peg$c1;
  524. }
  525. } else {
  526. peg$currPos = s0;
  527. s0 = peg$c1;
  528. }
  529. } else {
  530. peg$currPos = s0;
  531. s0 = peg$c1;
  532. }
  533. } else {
  534. peg$currPos = s0;
  535. s0 = peg$c1;
  536. }
  537. } else {
  538. peg$currPos = s0;
  539. s0 = peg$c1;
  540. }
  541. } else {
  542. peg$currPos = s0;
  543. s0 = peg$c1;
  544. }
  545. return s0;
  546. }
  547. function peg$parsemessageFormatElement() {
  548. var s0, s1, s2, s3, s4;
  549. s0 = peg$currPos;
  550. s1 = peg$parseid();
  551. if (s1 !== peg$FAILED) {
  552. s2 = peg$currPos;
  553. if (input.charCodeAt(peg$currPos) === 44) {
  554. s3 = peg$c10;
  555. peg$currPos++;
  556. } else {
  557. s3 = peg$FAILED;
  558. if (peg$silentFails === 0) { peg$fail(peg$c11); }
  559. }
  560. if (s3 !== peg$FAILED) {
  561. s4 = peg$parseelementFormat();
  562. if (s4 !== peg$FAILED) {
  563. s3 = [s3, s4];
  564. s2 = s3;
  565. } else {
  566. peg$currPos = s2;
  567. s2 = peg$c1;
  568. }
  569. } else {
  570. peg$currPos = s2;
  571. s2 = peg$c1;
  572. }
  573. if (s2 === peg$FAILED) {
  574. s2 = peg$c9;
  575. }
  576. if (s2 !== peg$FAILED) {
  577. peg$reportedPos = s0;
  578. s1 = peg$c12(s1, s2);
  579. s0 = s1;
  580. } else {
  581. peg$currPos = s0;
  582. s0 = peg$c1;
  583. }
  584. } else {
  585. peg$currPos = s0;
  586. s0 = peg$c1;
  587. }
  588. return s0;
  589. }
  590. function peg$parseelementFormat() {
  591. var s0, s1, s2, s3, s4, s5, s6, s7;
  592. s0 = peg$currPos;
  593. s1 = peg$parse_();
  594. if (s1 !== peg$FAILED) {
  595. if (input.substr(peg$currPos, 6) === peg$c13) {
  596. s2 = peg$c13;
  597. peg$currPos += 6;
  598. } else {
  599. s2 = peg$FAILED;
  600. if (peg$silentFails === 0) { peg$fail(peg$c14); }
  601. }
  602. if (s2 !== peg$FAILED) {
  603. s3 = peg$parse_();
  604. if (s3 !== peg$FAILED) {
  605. if (input.charCodeAt(peg$currPos) === 44) {
  606. s4 = peg$c10;
  607. peg$currPos++;
  608. } else {
  609. s4 = peg$FAILED;
  610. if (peg$silentFails === 0) { peg$fail(peg$c11); }
  611. }
  612. if (s4 !== peg$FAILED) {
  613. s5 = peg$parse_();
  614. if (s5 !== peg$FAILED) {
  615. s6 = peg$parsepluralStyle();
  616. if (s6 !== peg$FAILED) {
  617. s7 = peg$parse_();
  618. if (s7 !== peg$FAILED) {
  619. peg$reportedPos = s0;
  620. s1 = peg$c15(s2, s6);
  621. s0 = s1;
  622. } else {
  623. peg$currPos = s0;
  624. s0 = peg$c1;
  625. }
  626. } else {
  627. peg$currPos = s0;
  628. s0 = peg$c1;
  629. }
  630. } else {
  631. peg$currPos = s0;
  632. s0 = peg$c1;
  633. }
  634. } else {
  635. peg$currPos = s0;
  636. s0 = peg$c1;
  637. }
  638. } else {
  639. peg$currPos = s0;
  640. s0 = peg$c1;
  641. }
  642. } else {
  643. peg$currPos = s0;
  644. s0 = peg$c1;
  645. }
  646. } else {
  647. peg$currPos = s0;
  648. s0 = peg$c1;
  649. }
  650. if (s0 === peg$FAILED) {
  651. s0 = peg$currPos;
  652. s1 = peg$parse_();
  653. if (s1 !== peg$FAILED) {
  654. if (input.substr(peg$currPos, 13) === peg$c16) {
  655. s2 = peg$c16;
  656. peg$currPos += 13;
  657. } else {
  658. s2 = peg$FAILED;
  659. if (peg$silentFails === 0) { peg$fail(peg$c17); }
  660. }
  661. if (s2 !== peg$FAILED) {
  662. s3 = peg$parse_();
  663. if (s3 !== peg$FAILED) {
  664. if (input.charCodeAt(peg$currPos) === 44) {
  665. s4 = peg$c10;
  666. peg$currPos++;
  667. } else {
  668. s4 = peg$FAILED;
  669. if (peg$silentFails === 0) { peg$fail(peg$c11); }
  670. }
  671. if (s4 !== peg$FAILED) {
  672. s5 = peg$parse_();
  673. if (s5 !== peg$FAILED) {
  674. s6 = peg$parseselectStyle();
  675. if (s6 !== peg$FAILED) {
  676. s7 = peg$parse_();
  677. if (s7 !== peg$FAILED) {
  678. peg$reportedPos = s0;
  679. s1 = peg$c15(s2, s6);
  680. s0 = s1;
  681. } else {
  682. peg$currPos = s0;
  683. s0 = peg$c1;
  684. }
  685. } else {
  686. peg$currPos = s0;
  687. s0 = peg$c1;
  688. }
  689. } else {
  690. peg$currPos = s0;
  691. s0 = peg$c1;
  692. }
  693. } else {
  694. peg$currPos = s0;
  695. s0 = peg$c1;
  696. }
  697. } else {
  698. peg$currPos = s0;
  699. s0 = peg$c1;
  700. }
  701. } else {
  702. peg$currPos = s0;
  703. s0 = peg$c1;
  704. }
  705. } else {
  706. peg$currPos = s0;
  707. s0 = peg$c1;
  708. }
  709. if (s0 === peg$FAILED) {
  710. s0 = peg$currPos;
  711. s1 = peg$parse_();
  712. if (s1 !== peg$FAILED) {
  713. if (input.substr(peg$currPos, 6) === peg$c18) {
  714. s2 = peg$c18;
  715. peg$currPos += 6;
  716. } else {
  717. s2 = peg$FAILED;
  718. if (peg$silentFails === 0) { peg$fail(peg$c19); }
  719. }
  720. if (s2 !== peg$FAILED) {
  721. s3 = peg$parse_();
  722. if (s3 !== peg$FAILED) {
  723. if (input.charCodeAt(peg$currPos) === 44) {
  724. s4 = peg$c10;
  725. peg$currPos++;
  726. } else {
  727. s4 = peg$FAILED;
  728. if (peg$silentFails === 0) { peg$fail(peg$c11); }
  729. }
  730. if (s4 !== peg$FAILED) {
  731. s5 = peg$parse_();
  732. if (s5 !== peg$FAILED) {
  733. s6 = peg$parseselectStyle();
  734. if (s6 !== peg$FAILED) {
  735. s7 = peg$parse_();
  736. if (s7 !== peg$FAILED) {
  737. peg$reportedPos = s0;
  738. s1 = peg$c15(s2, s6);
  739. s0 = s1;
  740. } else {
  741. peg$currPos = s0;
  742. s0 = peg$c1;
  743. }
  744. } else {
  745. peg$currPos = s0;
  746. s0 = peg$c1;
  747. }
  748. } else {
  749. peg$currPos = s0;
  750. s0 = peg$c1;
  751. }
  752. } else {
  753. peg$currPos = s0;
  754. s0 = peg$c1;
  755. }
  756. } else {
  757. peg$currPos = s0;
  758. s0 = peg$c1;
  759. }
  760. } else {
  761. peg$currPos = s0;
  762. s0 = peg$c1;
  763. }
  764. } else {
  765. peg$currPos = s0;
  766. s0 = peg$c1;
  767. }
  768. if (s0 === peg$FAILED) {
  769. s0 = peg$currPos;
  770. s1 = peg$parse_();
  771. if (s1 !== peg$FAILED) {
  772. s2 = peg$parseid();
  773. if (s2 !== peg$FAILED) {
  774. s3 = [];
  775. s4 = peg$parseargStylePattern();
  776. while (s4 !== peg$FAILED) {
  777. s3.push(s4);
  778. s4 = peg$parseargStylePattern();
  779. }
  780. if (s3 !== peg$FAILED) {
  781. peg$reportedPos = s0;
  782. s1 = peg$c20(s2, s3);
  783. s0 = s1;
  784. } else {
  785. peg$currPos = s0;
  786. s0 = peg$c1;
  787. }
  788. } else {
  789. peg$currPos = s0;
  790. s0 = peg$c1;
  791. }
  792. } else {
  793. peg$currPos = s0;
  794. s0 = peg$c1;
  795. }
  796. }
  797. }
  798. }
  799. return s0;
  800. }
  801. function peg$parsepluralStyle() {
  802. var s0, s1;
  803. s0 = peg$currPos;
  804. s1 = peg$parsepluralFormatPattern();
  805. if (s1 !== peg$FAILED) {
  806. peg$reportedPos = s0;
  807. s1 = peg$c21(s1);
  808. }
  809. s0 = s1;
  810. return s0;
  811. }
  812. function peg$parseselectStyle() {
  813. var s0, s1;
  814. s0 = peg$currPos;
  815. s1 = peg$parseselectFormatPattern();
  816. if (s1 !== peg$FAILED) {
  817. peg$reportedPos = s0;
  818. s1 = peg$c22(s1);
  819. }
  820. s0 = s1;
  821. return s0;
  822. }
  823. function peg$parsepluralFormatPattern() {
  824. var s0, s1, s2, s3;
  825. s0 = peg$currPos;
  826. s1 = peg$parseoffsetPattern();
  827. if (s1 === peg$FAILED) {
  828. s1 = peg$c9;
  829. }
  830. if (s1 !== peg$FAILED) {
  831. s2 = [];
  832. s3 = peg$parsepluralForms();
  833. while (s3 !== peg$FAILED) {
  834. s2.push(s3);
  835. s3 = peg$parsepluralForms();
  836. }
  837. if (s2 !== peg$FAILED) {
  838. peg$reportedPos = s0;
  839. s1 = peg$c23(s1, s2);
  840. s0 = s1;
  841. } else {
  842. peg$currPos = s0;
  843. s0 = peg$c1;
  844. }
  845. } else {
  846. peg$currPos = s0;
  847. s0 = peg$c1;
  848. }
  849. return s0;
  850. }
  851. function peg$parseoffsetPattern() {
  852. var s0, s1, s2, s3, s4, s5, s6, s7;
  853. s0 = peg$currPos;
  854. s1 = peg$parse_();
  855. if (s1 !== peg$FAILED) {
  856. if (input.substr(peg$currPos, 6) === peg$c24) {
  857. s2 = peg$c24;
  858. peg$currPos += 6;
  859. } else {
  860. s2 = peg$FAILED;
  861. if (peg$silentFails === 0) { peg$fail(peg$c25); }
  862. }
  863. if (s2 !== peg$FAILED) {
  864. s3 = peg$parse_();
  865. if (s3 !== peg$FAILED) {
  866. if (input.charCodeAt(peg$currPos) === 58) {
  867. s4 = peg$c26;
  868. peg$currPos++;
  869. } else {
  870. s4 = peg$FAILED;
  871. if (peg$silentFails === 0) { peg$fail(peg$c27); }
  872. }
  873. if (s4 !== peg$FAILED) {
  874. s5 = peg$parse_();
  875. if (s5 !== peg$FAILED) {
  876. s6 = peg$parsedigits();
  877. if (s6 !== peg$FAILED) {
  878. s7 = peg$parse_();
  879. if (s7 !== peg$FAILED) {
  880. peg$reportedPos = s0;
  881. s1 = peg$c28(s6);
  882. s0 = s1;
  883. } else {
  884. peg$currPos = s0;
  885. s0 = peg$c1;
  886. }
  887. } else {
  888. peg$currPos = s0;
  889. s0 = peg$c1;
  890. }
  891. } else {
  892. peg$currPos = s0;
  893. s0 = peg$c1;
  894. }
  895. } else {
  896. peg$currPos = s0;
  897. s0 = peg$c1;
  898. }
  899. } else {
  900. peg$currPos = s0;
  901. s0 = peg$c1;
  902. }
  903. } else {
  904. peg$currPos = s0;
  905. s0 = peg$c1;
  906. }
  907. } else {
  908. peg$currPos = s0;
  909. s0 = peg$c1;
  910. }
  911. return s0;
  912. }
  913. function peg$parseselectFormatPattern() {
  914. var s0, s1, s2;
  915. s0 = peg$currPos;
  916. s1 = [];
  917. s2 = peg$parsepluralForms();
  918. while (s2 !== peg$FAILED) {
  919. s1.push(s2);
  920. s2 = peg$parsepluralForms();
  921. }
  922. if (s1 !== peg$FAILED) {
  923. peg$reportedPos = s0;
  924. s1 = peg$c29(s1);
  925. }
  926. s0 = s1;
  927. return s0;
  928. }
  929. function peg$parsepluralForms() {
  930. var s0, s1, s2, s3, s4, s5, s6, s7, s8;
  931. s0 = peg$currPos;
  932. s1 = peg$parse_();
  933. if (s1 !== peg$FAILED) {
  934. s2 = peg$parsestringKey();
  935. if (s2 !== peg$FAILED) {
  936. s3 = peg$parse_();
  937. if (s3 !== peg$FAILED) {
  938. if (input.charCodeAt(peg$currPos) === 123) {
  939. s4 = peg$c4;
  940. peg$currPos++;
  941. } else {
  942. s4 = peg$FAILED;
  943. if (peg$silentFails === 0) { peg$fail(peg$c5); }
  944. }
  945. if (s4 !== peg$FAILED) {
  946. s5 = peg$parse_();
  947. if (s5 !== peg$FAILED) {
  948. s6 = peg$parsemessageFormatPattern();
  949. if (s6 !== peg$FAILED) {
  950. s7 = peg$parse_();
  951. if (s7 !== peg$FAILED) {
  952. if (input.charCodeAt(peg$currPos) === 125) {
  953. s8 = peg$c6;
  954. peg$currPos++;
  955. } else {
  956. s8 = peg$FAILED;
  957. if (peg$silentFails === 0) { peg$fail(peg$c7); }
  958. }
  959. if (s8 !== peg$FAILED) {
  960. peg$reportedPos = s0;
  961. s1 = peg$c30(s2, s6);
  962. s0 = s1;
  963. } else {
  964. peg$currPos = s0;
  965. s0 = peg$c1;
  966. }
  967. } else {
  968. peg$currPos = s0;
  969. s0 = peg$c1;
  970. }
  971. } else {
  972. peg$currPos = s0;
  973. s0 = peg$c1;
  974. }
  975. } else {
  976. peg$currPos = s0;
  977. s0 = peg$c1;
  978. }
  979. } else {
  980. peg$currPos = s0;
  981. s0 = peg$c1;
  982. }
  983. } else {
  984. peg$currPos = s0;
  985. s0 = peg$c1;
  986. }
  987. } else {
  988. peg$currPos = s0;
  989. s0 = peg$c1;
  990. }
  991. } else {
  992. peg$currPos = s0;
  993. s0 = peg$c1;
  994. }
  995. return s0;
  996. }
  997. function peg$parsestringKey() {
  998. var s0, s1, s2;
  999. s0 = peg$currPos;
  1000. s1 = peg$parseid();
  1001. if (s1 !== peg$FAILED) {
  1002. peg$reportedPos = s0;
  1003. s1 = peg$c31(s1);
  1004. }
  1005. s0 = s1;
  1006. if (s0 === peg$FAILED) {
  1007. s0 = peg$currPos;
  1008. if (input.charCodeAt(peg$currPos) === 61) {
  1009. s1 = peg$c32;
  1010. peg$currPos++;
  1011. } else {
  1012. s1 = peg$FAILED;
  1013. if (peg$silentFails === 0) { peg$fail(peg$c33); }
  1014. }
  1015. if (s1 !== peg$FAILED) {
  1016. s2 = peg$parsedigits();
  1017. if (s2 !== peg$FAILED) {
  1018. peg$reportedPos = s0;
  1019. s1 = peg$c28(s2);
  1020. s0 = s1;
  1021. } else {
  1022. peg$currPos = s0;
  1023. s0 = peg$c1;
  1024. }
  1025. } else {
  1026. peg$currPos = s0;
  1027. s0 = peg$c1;
  1028. }
  1029. }
  1030. return s0;
  1031. }
  1032. function peg$parseargStylePattern() {
  1033. var s0, s1, s2, s3, s4, s5;
  1034. s0 = peg$currPos;
  1035. s1 = peg$parse_();
  1036. if (s1 !== peg$FAILED) {
  1037. if (input.charCodeAt(peg$currPos) === 44) {
  1038. s2 = peg$c10;
  1039. peg$currPos++;
  1040. } else {
  1041. s2 = peg$FAILED;
  1042. if (peg$silentFails === 0) { peg$fail(peg$c11); }
  1043. }
  1044. if (s2 !== peg$FAILED) {
  1045. s3 = peg$parse_();
  1046. if (s3 !== peg$FAILED) {
  1047. s4 = peg$parseid();
  1048. if (s4 !== peg$FAILED) {
  1049. s5 = peg$parse_();
  1050. if (s5 !== peg$FAILED) {
  1051. peg$reportedPos = s0;
  1052. s1 = peg$c34(s4);
  1053. s0 = s1;
  1054. } else {
  1055. peg$currPos = s0;
  1056. s0 = peg$c1;
  1057. }
  1058. } else {
  1059. peg$currPos = s0;
  1060. s0 = peg$c1;
  1061. }
  1062. } else {
  1063. peg$currPos = s0;
  1064. s0 = peg$c1;
  1065. }
  1066. } else {
  1067. peg$currPos = s0;
  1068. s0 = peg$c1;
  1069. }
  1070. } else {
  1071. peg$currPos = s0;
  1072. s0 = peg$c1;
  1073. }
  1074. return s0;
  1075. }
  1076. function peg$parsestring() {
  1077. var s0, s1, s2, s3, s4, s5, s6;
  1078. s0 = peg$currPos;
  1079. s1 = peg$parse_();
  1080. if (s1 !== peg$FAILED) {
  1081. s2 = [];
  1082. s3 = peg$currPos;
  1083. s4 = peg$parse_();
  1084. if (s4 !== peg$FAILED) {
  1085. s5 = peg$parsechars();
  1086. if (s5 !== peg$FAILED) {
  1087. s6 = peg$parse_();
  1088. if (s6 !== peg$FAILED) {
  1089. s4 = [s4, s5, s6];
  1090. s3 = s4;
  1091. } else {
  1092. peg$currPos = s3;
  1093. s3 = peg$c1;
  1094. }
  1095. } else {
  1096. peg$currPos = s3;
  1097. s3 = peg$c1;
  1098. }
  1099. } else {
  1100. peg$currPos = s3;
  1101. s3 = peg$c1;
  1102. }
  1103. while (s3 !== peg$FAILED) {
  1104. s2.push(s3);
  1105. s3 = peg$currPos;
  1106. s4 = peg$parse_();
  1107. if (s4 !== peg$FAILED) {
  1108. s5 = peg$parsechars();
  1109. if (s5 !== peg$FAILED) {
  1110. s6 = peg$parse_();
  1111. if (s6 !== peg$FAILED) {
  1112. s4 = [s4, s5, s6];
  1113. s3 = s4;
  1114. } else {
  1115. peg$currPos = s3;
  1116. s3 = peg$c1;
  1117. }
  1118. } else {
  1119. peg$currPos = s3;
  1120. s3 = peg$c1;
  1121. }
  1122. } else {
  1123. peg$currPos = s3;
  1124. s3 = peg$c1;
  1125. }
  1126. }
  1127. if (s2 !== peg$FAILED) {
  1128. peg$reportedPos = s0;
  1129. s1 = peg$c35(s1, s2);
  1130. s0 = s1;
  1131. } else {
  1132. peg$currPos = s0;
  1133. s0 = peg$c1;
  1134. }
  1135. } else {
  1136. peg$currPos = s0;
  1137. s0 = peg$c1;
  1138. }
  1139. return s0;
  1140. }
  1141. function peg$parseid() {
  1142. var s0, s1, s2, s3, s4;
  1143. s0 = peg$currPos;
  1144. s1 = peg$parse_();
  1145. if (s1 !== peg$FAILED) {
  1146. if (peg$c36.test(input.charAt(peg$currPos))) {
  1147. s2 = input.charAt(peg$currPos);
  1148. peg$currPos++;
  1149. } else {
  1150. s2 = peg$FAILED;
  1151. if (peg$silentFails === 0) { peg$fail(peg$c37); }
  1152. }
  1153. if (s2 !== peg$FAILED) {
  1154. s3 = [];
  1155. if (peg$c38.test(input.charAt(peg$currPos))) {
  1156. s4 = input.charAt(peg$currPos);
  1157. peg$currPos++;
  1158. } else {
  1159. s4 = peg$FAILED;
  1160. if (peg$silentFails === 0) { peg$fail(peg$c39); }
  1161. }
  1162. while (s4 !== peg$FAILED) {
  1163. s3.push(s4);
  1164. if (peg$c38.test(input.charAt(peg$currPos))) {
  1165. s4 = input.charAt(peg$currPos);
  1166. peg$currPos++;
  1167. } else {
  1168. s4 = peg$FAILED;
  1169. if (peg$silentFails === 0) { peg$fail(peg$c39); }
  1170. }
  1171. }
  1172. if (s3 !== peg$FAILED) {
  1173. s4 = peg$parse_();
  1174. if (s4 !== peg$FAILED) {
  1175. peg$reportedPos = s0;
  1176. s1 = peg$c40(s2, s3);
  1177. s0 = s1;
  1178. } else {
  1179. peg$currPos = s0;
  1180. s0 = peg$c1;
  1181. }
  1182. } else {
  1183. peg$currPos = s0;
  1184. s0 = peg$c1;
  1185. }
  1186. } else {
  1187. peg$currPos = s0;
  1188. s0 = peg$c1;
  1189. }
  1190. } else {
  1191. peg$currPos = s0;
  1192. s0 = peg$c1;
  1193. }
  1194. return s0;
  1195. }
  1196. function peg$parsechars() {
  1197. var s0, s1, s2;
  1198. s0 = peg$currPos;
  1199. s1 = [];
  1200. s2 = peg$parsechar();
  1201. if (s2 !== peg$FAILED) {
  1202. while (s2 !== peg$FAILED) {
  1203. s1.push(s2);
  1204. s2 = peg$parsechar();
  1205. }
  1206. } else {
  1207. s1 = peg$c1;
  1208. }
  1209. if (s1 !== peg$FAILED) {
  1210. peg$reportedPos = s0;
  1211. s1 = peg$c41(s1);
  1212. }
  1213. s0 = s1;
  1214. return s0;
  1215. }
  1216. function peg$parsechar() {
  1217. var s0, s1, s2, s3, s4, s5;
  1218. s0 = peg$currPos;
  1219. if (peg$c42.test(input.charAt(peg$currPos))) {
  1220. s1 = input.charAt(peg$currPos);
  1221. peg$currPos++;
  1222. } else {
  1223. s1 = peg$FAILED;
  1224. if (peg$silentFails === 0) { peg$fail(peg$c43); }
  1225. }
  1226. if (s1 !== peg$FAILED) {
  1227. peg$reportedPos = s0;
  1228. s1 = peg$c44(s1);
  1229. }
  1230. s0 = s1;
  1231. if (s0 === peg$FAILED) {
  1232. s0 = peg$currPos;
  1233. if (input.substr(peg$currPos, 2) === peg$c45) {
  1234. s1 = peg$c45;
  1235. peg$currPos += 2;
  1236. } else {
  1237. s1 = peg$FAILED;
  1238. if (peg$silentFails === 0) { peg$fail(peg$c46); }
  1239. }
  1240. if (s1 !== peg$FAILED) {
  1241. peg$reportedPos = s0;
  1242. s1 = peg$c47();
  1243. }
  1244. s0 = s1;
  1245. if (s0 === peg$FAILED) {
  1246. s0 = peg$currPos;
  1247. if (input.substr(peg$currPos, 2) === peg$c48) {
  1248. s1 = peg$c48;
  1249. peg$currPos += 2;
  1250. } else {
  1251. s1 = peg$FAILED;
  1252. if (peg$silentFails === 0) { peg$fail(peg$c49); }
  1253. }
  1254. if (s1 !== peg$FAILED) {
  1255. peg$reportedPos = s0;
  1256. s1 = peg$c50();
  1257. }
  1258. s0 = s1;
  1259. if (s0 === peg$FAILED) {
  1260. s0 = peg$currPos;
  1261. if (input.substr(peg$currPos, 2) === peg$c51) {
  1262. s1 = peg$c51;
  1263. peg$currPos += 2;
  1264. } else {
  1265. s1 = peg$FAILED;
  1266. if (peg$silentFails === 0) { peg$fail(peg$c52); }
  1267. }
  1268. if (s1 !== peg$FAILED) {
  1269. peg$reportedPos = s0;
  1270. s1 = peg$c53();
  1271. }
  1272. s0 = s1;
  1273. if (s0 === peg$FAILED) {
  1274. s0 = peg$currPos;
  1275. if (input.substr(peg$currPos, 2) === peg$c54) {
  1276. s1 = peg$c54;
  1277. peg$currPos += 2;
  1278. } else {
  1279. s1 = peg$FAILED;
  1280. if (peg$silentFails === 0) { peg$fail(peg$c55); }
  1281. }
  1282. if (s1 !== peg$FAILED) {
  1283. s2 = peg$parsehexDigit();
  1284. if (s2 !== peg$FAILED) {
  1285. s3 = peg$parsehexDigit();
  1286. if (s3 !== peg$FAILED) {
  1287. s4 = peg$parsehexDigit();
  1288. if (s4 !== peg$FAILED) {
  1289. s5 = peg$parsehexDigit();
  1290. if (s5 !== peg$FAILED) {
  1291. peg$reportedPos = s0;
  1292. s1 = peg$c56(s2, s3, s4, s5);
  1293. s0 = s1;
  1294. } else {
  1295. peg$currPos = s0;
  1296. s0 = peg$c1;
  1297. }
  1298. } else {
  1299. peg$currPos = s0;
  1300. s0 = peg$c1;
  1301. }
  1302. } else {
  1303. peg$currPos = s0;
  1304. s0 = peg$c1;
  1305. }
  1306. } else {
  1307. peg$currPos = s0;
  1308. s0 = peg$c1;
  1309. }
  1310. } else {
  1311. peg$currPos = s0;
  1312. s0 = peg$c1;
  1313. }
  1314. }
  1315. }
  1316. }
  1317. }
  1318. return s0;
  1319. }
  1320. function peg$parsedigits() {
  1321. var s0, s1, s2;
  1322. s0 = peg$currPos;
  1323. s1 = [];
  1324. if (peg$c57.test(input.charAt(peg$currPos))) {
  1325. s2 = input.charAt(peg$currPos);
  1326. peg$currPos++;
  1327. } else {
  1328. s2 = peg$FAILED;
  1329. if (peg$silentFails === 0) { peg$fail(peg$c58); }
  1330. }
  1331. if (s2 !== peg$FAILED) {
  1332. while (s2 !== peg$FAILED) {
  1333. s1.push(s2);
  1334. if (peg$c57.test(input.charAt(peg$currPos))) {
  1335. s2 = input.charAt(peg$currPos);
  1336. peg$currPos++;
  1337. } else {
  1338. s2 = peg$FAILED;
  1339. if (peg$silentFails === 0) { peg$fail(peg$c58); }
  1340. }
  1341. }
  1342. } else {
  1343. s1 = peg$c1;
  1344. }
  1345. if (s1 !== peg$FAILED) {
  1346. peg$reportedPos = s0;
  1347. s1 = peg$c59(s1);
  1348. }
  1349. s0 = s1;
  1350. return s0;
  1351. }
  1352. function peg$parsehexDigit() {
  1353. var s0;
  1354. if (peg$c60.test(input.charAt(peg$currPos))) {
  1355. s0 = input.charAt(peg$currPos);
  1356. peg$currPos++;
  1357. } else {
  1358. s0 = peg$FAILED;
  1359. if (peg$silentFails === 0) { peg$fail(peg$c61); }
  1360. }
  1361. return s0;
  1362. }
  1363. function peg$parse_() {
  1364. var s0, s1, s2;
  1365. peg$silentFails++;
  1366. s0 = peg$currPos;
  1367. s1 = [];
  1368. s2 = peg$parsewhitespace();
  1369. while (s2 !== peg$FAILED) {
  1370. s1.push(s2);
  1371. s2 = peg$parsewhitespace();
  1372. }
  1373. if (s1 !== peg$FAILED) {
  1374. peg$reportedPos = s0;
  1375. s1 = peg$c63(s1);
  1376. }
  1377. s0 = s1;
  1378. peg$silentFails--;
  1379. if (s0 === peg$FAILED) {
  1380. s1 = peg$FAILED;
  1381. if (peg$silentFails === 0) { peg$fail(peg$c62); }
  1382. }
  1383. return s0;
  1384. }
  1385. function peg$parsewhitespace() {
  1386. var s0;
  1387. if (peg$c64.test(input.charAt(peg$currPos))) {
  1388. s0 = input.charAt(peg$currPos);
  1389. peg$currPos++;
  1390. } else {
  1391. s0 = peg$FAILED;
  1392. if (peg$silentFails === 0) { peg$fail(peg$c65); }
  1393. }
  1394. return s0;
  1395. }
  1396. peg$result = peg$startRuleFunction();
  1397. if (peg$result !== peg$FAILED && peg$currPos === input.length) {
  1398. return peg$result;
  1399. } else {
  1400. if (peg$result !== peg$FAILED && peg$currPos < input.length) {
  1401. peg$fail({ type: "end", description: "end of input" });
  1402. }
  1403. throw peg$buildException(null, peg$maxFailExpected, peg$maxFailPos);
  1404. }
  1405. }
  1406. return {
  1407. SyntaxError: SyntaxError,
  1408. parse: parse
  1409. };
  1410. })();
  1411. MessageFormat._parse = function () {
  1412. // Bind to itself so error handling works
  1413. return mparser.parse.apply( mparser, arguments );
  1414. };
  1415. var propname = function(s) {
  1416. return /^[A-Z_$][0-9A-Z_$]*$/i.test(s) ? s : JSON.stringify(s);
  1417. };
  1418. MessageFormat.prototype._precompile = function(ast, data) {
  1419. data = data || { keys: {}, offset: {} };
  1420. var r = [], i, tmp, args = [];
  1421. switch ( ast.type ) {
  1422. case 'messageFormatPattern':
  1423. for ( i = 0; i < ast.statements.length; ++i ) {
  1424. r.push(this._precompile( ast.statements[i], data ));
  1425. }
  1426. tmp = r.join('+') || '""';
  1427. return data.pf_count ? tmp : 'function(d){return ' + tmp + '}';
  1428. case 'messageFormatPatternRight':
  1429. for ( i = 0; i < ast.statements.length; ++i ) {
  1430. r.push(this._precompile( ast.statements[i], data ));
  1431. }
  1432. return r.join('+');
  1433. case 'messageFormatElement':
  1434. data.pf_count = data.pf_count || 0;
  1435. if ( ast.output ) {
  1436. return 'd[' + JSON.stringify(ast.argumentIndex) + ']';
  1437. }
  1438. else {
  1439. data.keys[data.pf_count] = JSON.stringify(ast.argumentIndex);
  1440. return this._precompile( ast.elementFormat, data );
  1441. }
  1442. return '';
  1443. case 'elementFormat':
  1444. var args = [ 'd[' + data.keys[data.pf_count] + ']' ];
  1445. switch (ast.key) {
  1446. case 'select':
  1447. args.push(this._precompile(ast.val, data));
  1448. return '_s(' + args.join(',') + ')';
  1449. case 'selectordinal':
  1450. args = args.concat([ 0, 'pf[' + JSON.stringify(this.lc[0]) + ']', this._precompile(ast.val, data), 1 ]);
  1451. return '_p(' + args.join(',') + ')';
  1452. case 'plural':
  1453. data.offset[data.pf_count || 0] = ast.val.offset || 0;
  1454. args = args.concat([ data.offset[data.pf_count] || 0, 'pf[' + JSON.stringify(this.lc[0]) + ']', this._precompile(ast.val, data) ]);
  1455. return '_p(' + args.join(',') + ')';
  1456. default:
  1457. if (this.withIntlSupport && !(ast.key in this.runtime.fmt) && (ast.key in MessageFormat.formatters)) {
  1458. tmp = MessageFormat.formatters[ast.key];
  1459. this.runtime.fmt[ast.key] = (typeof tmp(this) == 'function') ? tmp(this) : tmp;
  1460. }
  1461. args.push(JSON.stringify(this.lc));
  1462. if (ast.val && ast.val.length) args.push(JSON.stringify(ast.val.length == 1 ? ast.val[0] : ast.val));
  1463. return 'fmt.' + ast.key + '(' + args.join(',') + ')';
  1464. }
  1465. case 'pluralFormatPattern':
  1466. case 'selectFormatPattern':
  1467. data.pf_count = data.pf_count || 0;
  1468. if (ast.type == 'selectFormatPattern') data.offset[data.pf_count] = 0;
  1469. var needOther = true;
  1470. for ( i = 0; i < ast.pluralForms.length; ++i ) {
  1471. var key = ast.pluralForms[i].key;
  1472. if ( key === 'other' ) {
  1473. needOther = false;
  1474. }
  1475. var data_copy = JSON.parse(JSON.stringify(data));
  1476. data_copy.pf_count++;
  1477. r.push(propname(key) + ':' + this._precompile(ast.pluralForms[i].val, data_copy));
  1478. }
  1479. if ( needOther ) {
  1480. throw new Error("No 'other' form found in " + ast.type + " " + data.pf_count);
  1481. }
  1482. return '{' + r.join(',') + '}';
  1483. case 'string':
  1484. tmp = '"' + (ast.val || "").replace(/\n/g, '\\n').replace(/"/g, '\\"') + '"';
  1485. if ( data.pf_count ) {
  1486. args = [ 'd[' + data.keys[data.pf_count-1] + ']' ];
  1487. if (data.offset[data.pf_count-1]) args.push(data.offset[data.pf_count-1]);
  1488. tmp = tmp.replace(/(^|[^\\])#/g, '$1"+' + '_n(' + args.join(',') + ')+"');
  1489. tmp = tmp.replace(/^""\+/, '').replace(/\+""$/, '');
  1490. }
  1491. return tmp;
  1492. default:
  1493. throw new Error( 'Bad AST type: ' + ast.type );
  1494. }
  1495. };
  1496. MessageFormat.prototype.compile = function ( messages, opt ) {
  1497. var r = {}, lc0 = this.lc,
  1498. compileMsg = function(self, msg) {
  1499. try {
  1500. var ast = MessageFormat._parse(msg).program;
  1501. return self._precompile(ast);
  1502. } catch (e) {
  1503. throw new Error((ast ? 'Precompiler' : 'Parser') + ' error: ' + e.toString());
  1504. }
  1505. },
  1506. stringify = function(r) {
  1507. if (typeof r != 'object') return r;
  1508. var o = [];
  1509. for (var k in r) o.push(propname(k) + ':' + stringify(r[k]));
  1510. return '{\n' + o.join(',\n') + '}';
  1511. };
  1512. if (typeof messages == 'string') {
  1513. var f = new Function('_n,_p,_s,pf,fmt', 'return ' + compileMsg(this, messages));
  1514. return f(this.runtime._n, this.runtime._p, this.runtime._s, this.runtime.pf, this.runtime.fmt);
  1515. }
  1516. opt = opt || {};
  1517. for (var ns in messages) {
  1518. if (opt.locale) this.lc = opt.locale[ns] && [].concat(opt.locale[ns]) || lc0;
  1519. if (typeof messages[ns] == 'string') {
  1520. try { r[ns] = compileMsg(this, messages[ns]); }
  1521. catch (e) { e.message = e.message.replace(':', ' with `' + ns + '`:'); throw e; }
  1522. } else {
  1523. r[ns] = {};
  1524. for (var key in messages[ns]) {
  1525. try { r[ns][key] = compileMsg(this, messages[ns][key]); }
  1526. catch (e) { e.message = e.message.replace(':', ' with `' + key + '` in `' + ns + '`:'); throw e; }
  1527. }
  1528. }
  1529. }
  1530. this.lc = lc0;
  1531. var s = 'var\n' + this.runtime.toString() + ';\n\n';
  1532. switch (opt.global || '') {
  1533. case 'exports':
  1534. var o = [];
  1535. for (var k in r) o.push('exports[' + JSON.stringify(k) + '] = ' + stringify(r[k]));
  1536. return new Function(s + o.join(';\n'));
  1537. case 'module.exports':
  1538. return new Function(s + 'module.exports = ' + stringify(r));
  1539. case '':
  1540. return new Function(s + 'return ' + stringify(r));
  1541. default:
  1542. return new Function('G', s + 'G[' + JSON.stringify(opt.global) + '] = ' + stringify(r));
  1543. }
  1544. };
  1545. return MessageFormat;
  1546. }());
  1547. /* jshint ignore:end */
  1548. var validateMessageBundle = function( cldr ) {
  1549. validate(
  1550. "E_MISSING_MESSAGE_BUNDLE",
  1551. "Missing message bundle for locale `{locale}`.",
  1552. cldr.attributes.bundle && cldr.get( "globalize-messages/{bundle}" ) !== undefined,
  1553. {
  1554. locale: cldr.locale
  1555. }
  1556. );
  1557. };
  1558. var validateMessagePresence = function( path, value ) {
  1559. path = path.join( "/" );
  1560. validate( "E_MISSING_MESSAGE", "Missing required message content `{path}`.",
  1561. value !== undefined, { path: path } );
  1562. };
  1563. var validateMessageType = function( path, value ) {
  1564. path = path.join( "/" );
  1565. validate(
  1566. "E_INVALID_MESSAGE",
  1567. "Invalid message content `{path}`. {expected} expected.",
  1568. typeof value === "string",
  1569. {
  1570. expected: "a string",
  1571. path: path
  1572. }
  1573. );
  1574. };
  1575. var validateParameterTypeMessageVariables = function( value, name ) {
  1576. validateParameterType(
  1577. value,
  1578. name,
  1579. value === undefined || isPlainObject( value ) || Array.isArray( value ),
  1580. "Array or Plain Object"
  1581. );
  1582. };
  1583. var validatePluralModulePresence = function() {
  1584. validate( "E_MISSING_PLURAL_MODULE", "Plural module not loaded.",
  1585. Globalize.plural !== undefined, {} );
  1586. };
  1587. var slice = [].slice;
  1588. function MessageFormatInit( globalize, cldr ) {
  1589. var plural;
  1590. return new MessageFormat( cldr.locale, function( value ) {
  1591. if ( !plural ) {
  1592. validatePluralModulePresence();
  1593. plural = globalize.pluralGenerator();
  1594. }
  1595. return plural( value );
  1596. });
  1597. }
  1598. /**
  1599. * .loadMessages( json )
  1600. *
  1601. * @json [JSON]
  1602. *
  1603. * Load translation data.
  1604. */
  1605. Globalize.loadMessages = function( json ) {
  1606. var locale,
  1607. customData = {
  1608. "globalize-messages": json,
  1609. "main": {}
  1610. };
  1611. validateParameterPresence( json, "json" );
  1612. validateParameterTypePlainObject( json, "json" );
  1613. // Set available bundles by populating customData main dataset.
  1614. for ( locale in json ) {
  1615. if ( json.hasOwnProperty( locale ) ) {
  1616. customData.main[ locale ] = {};
  1617. }
  1618. }
  1619. Cldr.load( customData );
  1620. };
  1621. /**
  1622. * .messageFormatter( path )
  1623. *
  1624. * @path [String or Array]
  1625. *
  1626. * Format a message given its path.
  1627. */
  1628. Globalize.messageFormatter =
  1629. Globalize.prototype.messageFormatter = function( path ) {
  1630. var cldr, formatter, message;
  1631. validateParameterPresence( path, "path" );
  1632. validateParameterType( path, "path", typeof path === "string" || Array.isArray( path ),
  1633. "a String nor an Array" );
  1634. path = alwaysArray( path );
  1635. cldr = this.cldr;
  1636. validateDefaultLocale( cldr );
  1637. validateMessageBundle( cldr );
  1638. message = cldr.get( [ "globalize-messages/{bundle}" ].concat( path ) );
  1639. validateMessagePresence( path, message );
  1640. // If message is an Array, concatenate it.
  1641. if ( Array.isArray( message ) ) {
  1642. message = message.join( " " );
  1643. }
  1644. validateMessageType( path, message );
  1645. formatter = MessageFormatInit( this, cldr ).compile( message );
  1646. return function( variables ) {
  1647. if ( typeof variables === "number" || typeof variables === "string" ) {
  1648. variables = slice.call( arguments, 0 );
  1649. }
  1650. validateParameterTypeMessageVariables( variables, "variables" );
  1651. return formatter( variables );
  1652. };
  1653. };
  1654. /**
  1655. * .formatMessage( path [, variables] )
  1656. *
  1657. * @path [String or Array]
  1658. *
  1659. * @variables [Number, String, Array or Object]
  1660. *
  1661. * Format a message given its path.
  1662. */
  1663. Globalize.formatMessage =
  1664. Globalize.prototype.formatMessage = function( path /* , variables */ ) {
  1665. return this.messageFormatter( path ).apply( {}, slice.call( arguments, 1 ) );
  1666. };
  1667. return Globalize;
  1668. }));