intl-messageformat 1.0.3 → 1.3.0

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 (254) hide show
  1. package/README.md +45 -19
  2. package/dist/intl-messageformat-with-locales.js +1095 -346
  3. package/dist/intl-messageformat-with-locales.js.map +1 -1
  4. package/dist/intl-messageformat-with-locales.min.js +4 -2
  5. package/dist/intl-messageformat-with-locales.min.js.map +1 -1
  6. package/dist/intl-messageformat.js +309 -186
  7. package/dist/intl-messageformat.js.map +1 -1
  8. package/dist/intl-messageformat.min.js +1 -1
  9. package/dist/intl-messageformat.min.js.map +1 -1
  10. package/dist/locale-data/af.js +2 -1
  11. package/dist/locale-data/agq.js +1 -0
  12. package/dist/locale-data/ak.js +1 -1
  13. package/dist/locale-data/am.js +1 -1
  14. package/dist/locale-data/ar.js +28 -1
  15. package/dist/locale-data/as.js +1 -1
  16. package/dist/locale-data/asa.js +1 -1
  17. package/dist/locale-data/ast.js +1 -1
  18. package/dist/locale-data/az.js +4 -1
  19. package/dist/locale-data/bas.js +1 -0
  20. package/dist/locale-data/be.js +1 -1
  21. package/dist/locale-data/bem.js +1 -1
  22. package/dist/locale-data/bez.js +1 -1
  23. package/dist/locale-data/bg.js +1 -1
  24. package/dist/locale-data/bh.js +1 -0
  25. package/dist/locale-data/bm.js +2 -1
  26. package/dist/locale-data/bn.js +2 -1
  27. package/dist/locale-data/bo.js +2 -1
  28. package/dist/locale-data/br.js +1 -1
  29. package/dist/locale-data/brx.js +1 -1
  30. package/dist/locale-data/bs.js +3 -1
  31. package/dist/locale-data/ca.js +6 -1
  32. package/dist/locale-data/ce.js +1 -0
  33. package/dist/locale-data/cgg.js +1 -1
  34. package/dist/locale-data/chr.js +1 -1
  35. package/dist/locale-data/ckb.js +2 -0
  36. package/dist/locale-data/cs.js +1 -1
  37. package/dist/locale-data/cu.js +1 -0
  38. package/dist/locale-data/cy.js +1 -1
  39. package/dist/locale-data/da.js +2 -1
  40. package/dist/locale-data/dav.js +1 -0
  41. package/dist/locale-data/de.js +6 -1
  42. package/dist/locale-data/dje.js +1 -0
  43. package/dist/locale-data/dsb.js +1 -0
  44. package/dist/locale-data/dua.js +1 -0
  45. package/dist/locale-data/dv.js +1 -0
  46. package/dist/locale-data/dyo.js +1 -0
  47. package/dist/locale-data/dz.js +1 -1
  48. package/dist/locale-data/ebu.js +1 -0
  49. package/dist/locale-data/ee.js +2 -1
  50. package/dist/locale-data/el.js +2 -1
  51. package/dist/locale-data/en.js +107 -1
  52. package/dist/locale-data/eo.js +1 -1
  53. package/dist/locale-data/es.js +26 -1
  54. package/dist/locale-data/et.js +1 -1
  55. package/dist/locale-data/eu.js +1 -1
  56. package/dist/locale-data/ewo.js +1 -0
  57. package/dist/locale-data/fa.js +2 -1
  58. package/dist/locale-data/ff.js +4 -1
  59. package/dist/locale-data/fi.js +1 -1
  60. package/dist/locale-data/fil.js +1 -1
  61. package/dist/locale-data/fo.js +2 -1
  62. package/dist/locale-data/fr.js +46 -1
  63. package/dist/locale-data/fur.js +1 -1
  64. package/dist/locale-data/fy.js +1 -1
  65. package/dist/locale-data/ga.js +1 -1
  66. package/dist/locale-data/gd.js +1 -1
  67. package/dist/locale-data/gl.js +1 -1
  68. package/dist/locale-data/gsw.js +3 -1
  69. package/dist/locale-data/gu.js +1 -1
  70. package/dist/locale-data/guw.js +1 -0
  71. package/dist/locale-data/guz.js +1 -0
  72. package/dist/locale-data/gv.js +1 -1
  73. package/dist/locale-data/ha.js +4 -1
  74. package/dist/locale-data/haw.js +1 -1
  75. package/dist/locale-data/he.js +1 -1
  76. package/dist/locale-data/hi.js +1 -1
  77. package/dist/locale-data/hr.js +2 -1
  78. package/dist/locale-data/hsb.js +1 -0
  79. package/dist/locale-data/hu.js +1 -1
  80. package/dist/locale-data/hy.js +1 -1
  81. package/dist/locale-data/id.js +1 -1
  82. package/dist/locale-data/ig.js +1 -1
  83. package/dist/locale-data/ii.js +1 -1
  84. package/dist/locale-data/in.js +1 -0
  85. package/dist/locale-data/is.js +1 -1
  86. package/dist/locale-data/it.js +3 -1
  87. package/dist/locale-data/iu.js +2 -0
  88. package/dist/locale-data/iw.js +1 -0
  89. package/dist/locale-data/ja.js +1 -1
  90. package/dist/locale-data/jbo.js +1 -0
  91. package/dist/locale-data/jgo.js +1 -1
  92. package/dist/locale-data/ji.js +1 -0
  93. package/dist/locale-data/jmc.js +1 -1
  94. package/dist/locale-data/jv.js +1 -0
  95. package/dist/locale-data/jw.js +1 -0
  96. package/dist/locale-data/ka.js +1 -1
  97. package/dist/locale-data/kab.js +1 -1
  98. package/dist/locale-data/kaj.js +1 -0
  99. package/dist/locale-data/kam.js +1 -0
  100. package/dist/locale-data/kcg.js +1 -0
  101. package/dist/locale-data/kde.js +1 -1
  102. package/dist/locale-data/kea.js +1 -1
  103. package/dist/locale-data/khq.js +1 -0
  104. package/dist/locale-data/ki.js +1 -0
  105. package/dist/locale-data/kk.js +1 -1
  106. package/dist/locale-data/kkj.js +1 -1
  107. package/dist/locale-data/kl.js +1 -1
  108. package/dist/locale-data/kln.js +1 -0
  109. package/dist/locale-data/km.js +1 -1
  110. package/dist/locale-data/kn.js +1 -1
  111. package/dist/locale-data/ko.js +2 -1
  112. package/dist/locale-data/kok.js +1 -0
  113. package/dist/locale-data/ks.js +1 -1
  114. package/dist/locale-data/ksb.js +1 -1
  115. package/dist/locale-data/ksf.js +1 -0
  116. package/dist/locale-data/ksh.js +1 -1
  117. package/dist/locale-data/ku.js +1 -0
  118. package/dist/locale-data/kw.js +1 -1
  119. package/dist/locale-data/ky.js +1 -1
  120. package/dist/locale-data/lag.js +1 -1
  121. package/dist/locale-data/lb.js +1 -0
  122. package/dist/locale-data/lg.js +1 -1
  123. package/dist/locale-data/lkt.js +1 -1
  124. package/dist/locale-data/ln.js +4 -1
  125. package/dist/locale-data/lo.js +1 -1
  126. package/dist/locale-data/lrc.js +2 -0
  127. package/dist/locale-data/lt.js +1 -1
  128. package/dist/locale-data/lu.js +1 -0
  129. package/dist/locale-data/luo.js +1 -0
  130. package/dist/locale-data/luy.js +1 -0
  131. package/dist/locale-data/lv.js +1 -1
  132. package/dist/locale-data/mas.js +2 -1
  133. package/dist/locale-data/mer.js +1 -0
  134. package/dist/locale-data/mfe.js +1 -0
  135. package/dist/locale-data/mg.js +1 -1
  136. package/dist/locale-data/mgh.js +1 -0
  137. package/dist/locale-data/mgo.js +1 -1
  138. package/dist/locale-data/mk.js +1 -1
  139. package/dist/locale-data/ml.js +1 -1
  140. package/dist/locale-data/mn.js +2 -1
  141. package/dist/locale-data/mo.js +1 -0
  142. package/dist/locale-data/mr.js +1 -1
  143. package/dist/locale-data/ms.js +4 -1
  144. package/dist/locale-data/mt.js +1 -1
  145. package/dist/locale-data/mua.js +1 -0
  146. package/dist/locale-data/my.js +1 -1
  147. package/dist/locale-data/mzn.js +1 -0
  148. package/dist/locale-data/nah.js +1 -0
  149. package/dist/locale-data/naq.js +1 -1
  150. package/dist/locale-data/nb.js +2 -1
  151. package/dist/locale-data/nd.js +1 -1
  152. package/dist/locale-data/ne.js +2 -1
  153. package/dist/locale-data/nl.js +7 -1
  154. package/dist/locale-data/nmg.js +1 -0
  155. package/dist/locale-data/nn.js +1 -1
  156. package/dist/locale-data/nnh.js +1 -1
  157. package/dist/locale-data/no.js +1 -0
  158. package/dist/locale-data/nqo.js +1 -0
  159. package/dist/locale-data/nr.js +1 -1
  160. package/dist/locale-data/nso.js +1 -1
  161. package/dist/locale-data/nus.js +1 -0
  162. package/dist/locale-data/ny.js +1 -0
  163. package/dist/locale-data/nyn.js +1 -1
  164. package/dist/locale-data/om.js +2 -1
  165. package/dist/locale-data/or.js +1 -1
  166. package/dist/locale-data/os.js +2 -1
  167. package/dist/locale-data/pa.js +3 -1
  168. package/dist/locale-data/pap.js +1 -0
  169. package/dist/locale-data/pl.js +1 -1
  170. package/dist/locale-data/prg.js +1 -0
  171. package/dist/locale-data/ps.js +1 -1
  172. package/dist/locale-data/pt.js +9 -1
  173. package/dist/locale-data/qu.js +3 -0
  174. package/dist/locale-data/rm.js +1 -1
  175. package/dist/locale-data/rn.js +1 -0
  176. package/dist/locale-data/ro.js +2 -1
  177. package/dist/locale-data/rof.js +1 -1
  178. package/dist/locale-data/ru.js +6 -1
  179. package/dist/locale-data/rw.js +1 -0
  180. package/dist/locale-data/rwk.js +1 -1
  181. package/dist/locale-data/sah.js +1 -1
  182. package/dist/locale-data/saq.js +1 -1
  183. package/dist/locale-data/sbp.js +1 -0
  184. package/dist/locale-data/sdh.js +1 -0
  185. package/dist/locale-data/se.js +3 -1
  186. package/dist/locale-data/seh.js +1 -1
  187. package/dist/locale-data/ses.js +1 -1
  188. package/dist/locale-data/sg.js +1 -1
  189. package/dist/locale-data/sh.js +1 -0
  190. package/dist/locale-data/shi.js +3 -1
  191. package/dist/locale-data/si.js +1 -1
  192. package/dist/locale-data/sk.js +1 -1
  193. package/dist/locale-data/sl.js +1 -1
  194. package/dist/locale-data/sma.js +1 -0
  195. package/dist/locale-data/smi.js +1 -0
  196. package/dist/locale-data/smj.js +1 -0
  197. package/dist/locale-data/smn.js +1 -0
  198. package/dist/locale-data/sms.js +1 -0
  199. package/dist/locale-data/sn.js +1 -1
  200. package/dist/locale-data/so.js +4 -1
  201. package/dist/locale-data/sq.js +3 -1
  202. package/dist/locale-data/sr.js +9 -1
  203. package/dist/locale-data/ss.js +1 -1
  204. package/dist/locale-data/ssy.js +1 -1
  205. package/dist/locale-data/st.js +1 -1
  206. package/dist/locale-data/sv.js +3 -1
  207. package/dist/locale-data/sw.js +4 -1
  208. package/dist/locale-data/syr.js +1 -0
  209. package/dist/locale-data/ta.js +4 -1
  210. package/dist/locale-data/te.js +1 -1
  211. package/dist/locale-data/teo.js +2 -1
  212. package/dist/locale-data/th.js +1 -1
  213. package/dist/locale-data/ti.js +2 -1
  214. package/dist/locale-data/tig.js +1 -1
  215. package/dist/locale-data/tk.js +1 -0
  216. package/dist/locale-data/tl.js +1 -0
  217. package/dist/locale-data/tn.js +1 -1
  218. package/dist/locale-data/to.js +1 -1
  219. package/dist/locale-data/tr.js +2 -1
  220. package/dist/locale-data/ts.js +1 -1
  221. package/dist/locale-data/twq.js +1 -0
  222. package/dist/locale-data/tzm.js +1 -1
  223. package/dist/locale-data/ug.js +1 -1
  224. package/dist/locale-data/uk.js +1 -1
  225. package/dist/locale-data/ur.js +2 -1
  226. package/dist/locale-data/uz.js +4 -1
  227. package/dist/locale-data/vai.js +3 -0
  228. package/dist/locale-data/ve.js +1 -1
  229. package/dist/locale-data/vi.js +1 -1
  230. package/dist/locale-data/vo.js +1 -1
  231. package/dist/locale-data/vun.js +1 -1
  232. package/dist/locale-data/wa.js +1 -0
  233. package/dist/locale-data/wae.js +1 -1
  234. package/dist/locale-data/wo.js +1 -0
  235. package/dist/locale-data/xh.js +1 -1
  236. package/dist/locale-data/xog.js +1 -1
  237. package/dist/locale-data/yav.js +1 -0
  238. package/dist/locale-data/yi.js +1 -0
  239. package/dist/locale-data/yo.js +2 -1
  240. package/dist/locale-data/zgh.js +1 -0
  241. package/dist/locale-data/zh.js +8 -1
  242. package/dist/locale-data/zu.js +1 -1
  243. package/lib/compiler.js +21 -10
  244. package/lib/core.js +54 -35
  245. package/lib/en.js +2 -1
  246. package/lib/es5.js +8 -0
  247. package/lib/locales.js +554 -161
  248. package/lib/main.js +5 -3
  249. package/lib/utils.js +8 -0
  250. package/package.json +10 -9
  251. package/src/compiler.js +13 -10
  252. package/src/core.js +44 -33
  253. package/src/en.js +1 -1
  254. package/bower.json +0 -40
package/lib/main.js CHANGED
@@ -1,9 +1,11 @@
1
+ /* jslint esnext: true */
2
+
1
3
  "use strict";
2
4
  var src$core$$ = require("./core"), src$en$$ = require("./en");
3
5
 
4
- src$core$$.default.__addLocaleData(src$en$$.default);
5
- src$core$$.default.defaultLocale = 'en';
6
+ src$core$$["default"].__addLocaleData(src$en$$["default"]);
7
+ src$core$$["default"].defaultLocale = 'en';
6
8
 
7
- exports["default"] = src$core$$.default;
9
+ exports["default"] = src$core$$["default"];
8
10
 
9
11
  //# sourceMappingURL=main.js.map
package/lib/utils.js CHANGED
@@ -1,3 +1,11 @@
1
+ /*
2
+ Copyright (c) 2014, Yahoo! Inc. All rights reserved.
3
+ Copyrights licensed under the New BSD License.
4
+ See the accompanying LICENSE file for terms.
5
+ */
6
+
7
+ /* jslint esnext: true */
8
+
1
9
  "use strict";
2
10
  exports.extend = extend;
3
11
  var hop = Object.prototype.hasOwnProperty;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intl-messageformat",
3
- "version": "1.0.3",
3
+ "version": "1.3.0",
4
4
  "description": "Formats ICU Message strings with number, date, plural, and select placeholders to create localized messages.",
5
5
  "keywords": [
6
6
  "i18n",
@@ -33,22 +33,23 @@
33
33
  "./lib/locales.js": false
34
34
  },
35
35
  "dependencies": {
36
- "intl-messageformat-parser": "1.0.1"
36
+ "intl-messageformat-parser": "1.2.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "benchmark": "^1.0.0",
40
40
  "expect.js": "^0.3.1",
41
41
  "grunt": "^0.4.5",
42
42
  "grunt-benchmark": "^0.3.0",
43
- "grunt-bundle-jsnext-lib": "^0.4.1",
43
+ "grunt-browserify": "^3.3.0",
44
+ "grunt-bundle-jsnext-lib": "^0.5.0",
44
45
  "grunt-cli": "^0.1.13",
45
46
  "grunt-contrib-clean": "^0.6.0",
46
47
  "grunt-contrib-concat": "^0.5.0",
47
48
  "grunt-contrib-connect": "^0.9.0",
48
- "grunt-contrib-copy": "^0.7.0",
49
- "grunt-contrib-jshint": "^0.10.0",
50
- "grunt-contrib-uglify": "^0.7.0",
51
- "grunt-extract-cldr-data": "^1.1.0",
49
+ "grunt-contrib-copy": "^0.8.0",
50
+ "grunt-contrib-jshint": "^0.11.0",
51
+ "grunt-contrib-uglify": "^0.8.0",
52
+ "grunt-extract-cldr-data": "^3.0.0",
52
53
  "grunt-json-remove-fields": "git://github.com/ericf/grunt-json-remove-fields#improve-files-and-output",
53
54
  "grunt-saucelabs": "^8.4.1",
54
55
  "intl": "^0.1.4",
@@ -57,7 +58,7 @@
57
58
  "xunit-file": "0.0.6"
58
59
  },
59
60
  "scripts": {
60
- "test": "istanbul cover -x lib/locales.js -- ./node_modules/mocha/bin/_mocha tests/runner.js --reporter spec",
61
+ "test": "istanbul cover -x lib/locales.js -- _mocha tests/runner.js --reporter spec",
61
62
  "travis": "istanbul cover -x lib/locales.js -- _mocha tests/runner.js --reporter spec && tests/saucelabs.sh",
62
63
  "prepublish": "grunt"
63
64
  },
@@ -65,5 +66,5 @@
65
66
  "directories": {
66
67
  "test": "tests"
67
68
  },
68
- "license": "BSD"
69
+ "license": "BSD-3-Clause"
69
70
  }
package/src/compiler.js CHANGED
@@ -110,7 +110,9 @@ Compiler.prototype.compileArgument = function (element) {
110
110
 
111
111
  case 'pluralFormat':
112
112
  options = this.compileOptions(element);
113
- return new PluralFormat(element.id, format.offset, options, pluralFn);
113
+ return new PluralFormat(
114
+ element.id, format.ordinal, format.offset, options, pluralFn
115
+ );
114
116
 
115
117
  case 'selectFormat':
116
118
  options = this.compileOptions(element);
@@ -127,8 +129,8 @@ Compiler.prototype.compileOptions = function (element) {
127
129
  optionsHash = {};
128
130
 
129
131
  // Save the current plural element, if any, then set it to a new value when
130
- // compiling the options sub-patterns. This conform's the spec's algorithm
131
- // for handling `"#"` synax in message text.
132
+ // compiling the options sub-patterns. This conforms the spec's algorithm
133
+ // for handling `"#"` syntax in message text.
132
134
  this.pluralStack.push(this.currentPlural);
133
135
  this.currentPlural = format.type === 'pluralFormat' ? element : null;
134
136
 
@@ -141,7 +143,7 @@ Compiler.prototype.compileOptions = function (element) {
141
143
  optionsHash[option.selector] = this.compileMessage(option.value);
142
144
  }
143
145
 
144
- // Pop the plural stack to put back the original currnet plural value.
146
+ // Pop the plural stack to put back the original current plural value.
145
147
  this.currentPlural = this.pluralStack.pop();
146
148
 
147
149
  return optionsHash;
@@ -161,18 +163,19 @@ StringFormat.prototype.format = function (value) {
161
163
  return typeof value === 'string' ? value : String(value);
162
164
  };
163
165
 
164
- function PluralFormat(id, offset, options, pluralFn) {
165
- this.id = id;
166
- this.offset = offset;
167
- this.options = options;
168
- this.pluralFn = pluralFn;
166
+ function PluralFormat(id, useOrdinal, offset, options, pluralFn) {
167
+ this.id = id;
168
+ this.useOrdinal = useOrdinal;
169
+ this.offset = offset;
170
+ this.options = options;
171
+ this.pluralFn = pluralFn;
169
172
  }
170
173
 
171
174
  PluralFormat.prototype.getOption = function (value) {
172
175
  var options = this.options;
173
176
 
174
177
  var option = options['=' + value] ||
175
- options[this.pluralFn(value - this.offset)];
178
+ options[this.pluralFn(value - this.offset, this.useOrdinal)];
176
179
 
177
180
  return option || options.other;
178
181
  };
package/src/core.js CHANGED
@@ -31,12 +31,11 @@ function MessageFormat(message, locales, formats) {
31
31
  // Defined first because it's used to build the format pattern.
32
32
  defineProperty(this, '_locale', {value: this._resolveLocale(locales)});
33
33
 
34
- var pluralFn = MessageFormat.__localeData__[this._locale].pluralRuleFunction;
35
-
36
34
  // Compile the `ast` to a pattern that is highly optimized for repeated
37
35
  // `format()` invocations. **Note:** This passes the `locales` set provided
38
36
  // to the constructor instead of just the resolved locale.
39
- var pattern = this._compilePattern(ast, locales, formats, pluralFn);
37
+ var pluralFn = this._findPluralRuleFunction(this._locale);
38
+ var pattern = this._compilePattern(ast, locales, formats, pluralFn);
40
39
 
41
40
  // "Bind" `format()` method to `this` so it can be passed by reference like
42
41
  // the other `Intl` APIs.
@@ -129,17 +128,7 @@ defineProperty(MessageFormat, '__addLocaleData', {value: function (data) {
129
128
  );
130
129
  }
131
130
 
132
- if (!data.pluralRuleFunction) {
133
- throw new Error(
134
- 'Locale data provided to IntlMessageFormat is missing a ' +
135
- '`pluralRuleFunction` property'
136
- );
137
- }
138
-
139
- // Message format locale data only requires the first part of the tag.
140
- var locale = data.locale.toLowerCase().split('-')[0];
141
-
142
- MessageFormat.__localeData__[locale] = data;
131
+ MessageFormat.__localeData__[data.locale.toLowerCase()] = data;
143
132
  }});
144
133
 
145
134
  // Defines `__parse()` static method as an exposed private.
@@ -165,6 +154,26 @@ MessageFormat.prototype._compilePattern = function (ast, locales, formats, plura
165
154
  return compiler.compile(ast);
166
155
  };
167
156
 
157
+ MessageFormat.prototype._findPluralRuleFunction = function (locale) {
158
+ var localeData = MessageFormat.__localeData__;
159
+ var data = localeData[locale.toLowerCase()];
160
+
161
+ // The locale data is de-duplicated, so we have to traverse the locale's
162
+ // hierarchy until we find a `pluralRuleFunction` to return.
163
+ while (data) {
164
+ if (data.pluralRuleFunction) {
165
+ return data.pluralRuleFunction;
166
+ }
167
+
168
+ data = data.parentLocale && localeData[data.parentLocale.toLowerCase()];
169
+ }
170
+
171
+ throw new Error(
172
+ 'Locale data added to IntlMessageFormat is missing a ' +
173
+ '`pluralRuleFunction` for :' + locale
174
+ );
175
+ };
176
+
168
177
  MessageFormat.prototype._format = function (pattern, values) {
169
178
  var result = '',
170
179
  i, len, part, id, value;
@@ -218,37 +227,39 @@ MessageFormat.prototype._mergeFormats = function (defaults, formats) {
218
227
  };
219
228
 
220
229
  MessageFormat.prototype._resolveLocale = function (locales) {
221
- if (!locales) {
222
- locales = MessageFormat.defaultLocale;
223
- }
224
-
225
230
  if (typeof locales === 'string') {
226
231
  locales = [locales];
227
232
  }
228
233
 
234
+ // Create a copy of the array so we can push on the default locale.
235
+ locales = (locales || []).concat(MessageFormat.defaultLocale);
236
+
229
237
  var localeData = MessageFormat.__localeData__;
230
- var i, len, locale;
238
+ var i, len, localeParts, data;
231
239
 
240
+ // Using the set of locales + the default locale, we look for the first one
241
+ // which that has been registered. When data does not exist for a locale, we
242
+ // traverse its ancestors to find something that's been registered within
243
+ // its hierarchy of locales. Since we lack the proper `parentLocale` data
244
+ // here, we must take a naive approach to traversal.
232
245
  for (i = 0, len = locales.length; i < len; i += 1) {
233
- // We just need the root part of the langage tag.
234
- locale = locales[i].split('-')[0].toLowerCase();
235
-
236
- // Validate that the langage tag is structurally valid.
237
- if (!/[a-z]{2,3}/.test(locale)) {
238
- throw new Error(
239
- 'Language tag provided to IntlMessageFormat is not ' +
240
- 'structrually valid: ' + locale
241
- );
242
- }
246
+ localeParts = locales[i].toLowerCase().split('-');
247
+
248
+ while (localeParts.length) {
249
+ data = localeData[localeParts.join('-')];
250
+ if (data) {
251
+ // Return the normalized locale string; e.g., we return "en-US",
252
+ // instead of "en-us".
253
+ return data.locale;
254
+ }
243
255
 
244
- // Return the first locale for which we have CLDR data registered.
245
- if (hop.call(localeData, locale)) {
246
- return locale;
256
+ localeParts.pop();
247
257
  }
248
258
  }
249
259
 
260
+ var defaultLocale = locales.pop();
250
261
  throw new Error(
251
262
  'No locale data has been added to IntlMessageFormat for: ' +
252
- locales.join(', ')
263
+ locales.join(', ') + ', or the default locale: ' + defaultLocale
253
264
  );
254
265
  };
package/src/en.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // GENERATED FILE
2
- export default {"locale":"en","pluralRuleFunction":function (n) {var i=Math.floor(Math.abs(n)),v=n.toString().replace(/^[^.]*\.?/,"").length;n=Math.floor(n);if(i===1&&v===0)return"one";return"other";}};
2
+ export default {"locale":"en","pluralRuleFunction":function (n,ord){var s=String(n).split("."),v0=!s[1],t0=Number(s[0])==n,n10=t0&&s[0].slice(-1),n100=t0&&s[0].slice(-2);if(ord)return n10==1&&n100!=11?"one":n10==2&&n100!=12?"two":n10==3&&n100!=13?"few":"other";return n==1&&v0?"one":"other"}};
package/bower.json DELETED
@@ -1,40 +0,0 @@
1
- {
2
- "name": "intl-messageformat",
3
- "main": [
4
- "dist/intl-messageformat.js"
5
- ],
6
- "version": "1.0.1",
7
- "homepage": "https://github.com/yahoo/intl-messageformat",
8
- "authors": [
9
- "Eric Ferraiuolo <eferraiuolo@gmail.com>",
10
- "Drew Folta <drew@folta.net>",
11
- "Caridy Patino <caridy@gmail.com>",
12
- "Anthony Pipkin <a.pipkin@yahoo.com>"
13
- ],
14
- "description": "Formats ICU Message strings with number, date, plural, and select placeholders to create localized messages.",
15
- "keywords": [
16
- "i18n",
17
- "intl",
18
- "internationalization",
19
- "localization",
20
- "globalization",
21
- "messageformat",
22
- "parser",
23
- "plural",
24
- "icu"
25
- ],
26
- "license": "BSD",
27
- "ignore": [
28
- "**/.*",
29
- "!dist/*",
30
- "node_modules",
31
- "bower_components",
32
- "test",
33
- "tests"
34
- ],
35
- "moduleType": [
36
- "es6",
37
- "commonjs",
38
- "globals"
39
- ]
40
- }