intl-messageformat 1.0.1 → 1.1.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 (253) hide show
  1. package/README.md +44 -18
  2. package/dist/intl-messageformat-with-locales.js +1249 -321
  3. package/dist/intl-messageformat-with-locales.js.map +1 -0
  4. package/dist/intl-messageformat-with-locales.min.js +4 -2
  5. package/dist/intl-messageformat-with-locales.min.js.map +1 -0
  6. package/dist/intl-messageformat.js +265 -160
  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/aa.js +4 -0
  11. package/dist/locale-data/af.js +3 -1
  12. package/dist/locale-data/agq.js +2 -0
  13. package/dist/locale-data/ak.js +2 -1
  14. package/dist/locale-data/am.js +2 -1
  15. package/dist/locale-data/ar.js +29 -1
  16. package/dist/locale-data/as.js +2 -1
  17. package/dist/locale-data/asa.js +2 -1
  18. package/dist/locale-data/ast.js +2 -1
  19. package/dist/locale-data/az.js +5 -1
  20. package/dist/locale-data/bas.js +2 -0
  21. package/dist/locale-data/be.js +2 -1
  22. package/dist/locale-data/bem.js +2 -1
  23. package/dist/locale-data/bez.js +2 -1
  24. package/dist/locale-data/bg.js +2 -1
  25. package/dist/locale-data/bh.js +1 -0
  26. package/dist/locale-data/bm.js +4 -1
  27. package/dist/locale-data/bn.js +3 -1
  28. package/dist/locale-data/bo.js +3 -1
  29. package/dist/locale-data/br.js +2 -1
  30. package/dist/locale-data/brx.js +2 -1
  31. package/dist/locale-data/bs.js +5 -1
  32. package/dist/locale-data/ca.js +6 -1
  33. package/dist/locale-data/cgg.js +2 -1
  34. package/dist/locale-data/chr.js +2 -1
  35. package/dist/locale-data/ckb.js +1 -0
  36. package/dist/locale-data/cs.js +2 -1
  37. package/dist/locale-data/cy.js +2 -1
  38. package/dist/locale-data/da.js +3 -1
  39. package/dist/locale-data/dav.js +2 -0
  40. package/dist/locale-data/de.js +7 -1
  41. package/dist/locale-data/dje.js +2 -0
  42. package/dist/locale-data/dsb.js +2 -0
  43. package/dist/locale-data/dua.js +2 -0
  44. package/dist/locale-data/dv.js +1 -0
  45. package/dist/locale-data/dyo.js +2 -0
  46. package/dist/locale-data/dz.js +2 -1
  47. package/dist/locale-data/ebu.js +2 -0
  48. package/dist/locale-data/ee.js +3 -1
  49. package/dist/locale-data/el.js +3 -1
  50. package/dist/locale-data/en.js +96 -1
  51. package/dist/locale-data/eo.js +2 -1
  52. package/dist/locale-data/es.js +27 -1
  53. package/dist/locale-data/et.js +2 -1
  54. package/dist/locale-data/eu.js +2 -1
  55. package/dist/locale-data/ewo.js +2 -0
  56. package/dist/locale-data/fa.js +3 -1
  57. package/dist/locale-data/ff.js +5 -1
  58. package/dist/locale-data/fi.js +2 -1
  59. package/dist/locale-data/fil.js +2 -1
  60. package/dist/locale-data/fo.js +2 -1
  61. package/dist/locale-data/fr.js +47 -1
  62. package/dist/locale-data/fur.js +2 -1
  63. package/dist/locale-data/fy.js +2 -1
  64. package/dist/locale-data/ga.js +2 -1
  65. package/dist/locale-data/gd.js +2 -1
  66. package/dist/locale-data/gl.js +2 -1
  67. package/dist/locale-data/gsw.js +4 -1
  68. package/dist/locale-data/gu.js +2 -1
  69. package/dist/locale-data/guw.js +1 -0
  70. package/dist/locale-data/guz.js +2 -0
  71. package/dist/locale-data/gv.js +2 -1
  72. package/dist/locale-data/ha.js +6 -1
  73. package/dist/locale-data/haw.js +2 -1
  74. package/dist/locale-data/he.js +2 -1
  75. package/dist/locale-data/hi.js +2 -1
  76. package/dist/locale-data/hr.js +3 -1
  77. package/dist/locale-data/hsb.js +2 -0
  78. package/dist/locale-data/hu.js +2 -1
  79. package/dist/locale-data/hy.js +2 -1
  80. package/dist/locale-data/ia.js +2 -0
  81. package/dist/locale-data/id.js +2 -1
  82. package/dist/locale-data/ig.js +2 -1
  83. package/dist/locale-data/ii.js +2 -1
  84. package/dist/locale-data/in.js +1 -0
  85. package/dist/locale-data/is.js +2 -1
  86. package/dist/locale-data/it.js +4 -1
  87. package/dist/locale-data/iu.js +1 -0
  88. package/dist/locale-data/iw.js +1 -0
  89. package/dist/locale-data/ja.js +2 -1
  90. package/dist/locale-data/jbo.js +1 -0
  91. package/dist/locale-data/jgo.js +2 -1
  92. package/dist/locale-data/ji.js +1 -0
  93. package/dist/locale-data/jmc.js +2 -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 +2 -1
  97. package/dist/locale-data/kab.js +2 -1
  98. package/dist/locale-data/kaj.js +1 -0
  99. package/dist/locale-data/kam.js +2 -0
  100. package/dist/locale-data/kcg.js +1 -0
  101. package/dist/locale-data/kde.js +2 -1
  102. package/dist/locale-data/kea.js +2 -1
  103. package/dist/locale-data/khq.js +2 -0
  104. package/dist/locale-data/ki.js +2 -0
  105. package/dist/locale-data/kk.js +3 -1
  106. package/dist/locale-data/kkj.js +2 -1
  107. package/dist/locale-data/kl.js +2 -1
  108. package/dist/locale-data/kln.js +2 -0
  109. package/dist/locale-data/km.js +2 -1
  110. package/dist/locale-data/kn.js +2 -1
  111. package/dist/locale-data/ko.js +3 -1
  112. package/dist/locale-data/kok.js +2 -0
  113. package/dist/locale-data/ks.js +3 -1
  114. package/dist/locale-data/ksb.js +2 -1
  115. package/dist/locale-data/ksf.js +2 -0
  116. package/dist/locale-data/ksh.js +2 -1
  117. package/dist/locale-data/ku.js +1 -0
  118. package/dist/locale-data/kw.js +2 -1
  119. package/dist/locale-data/ky.js +3 -1
  120. package/dist/locale-data/lag.js +2 -1
  121. package/dist/locale-data/lb.js +2 -0
  122. package/dist/locale-data/lg.js +2 -1
  123. package/dist/locale-data/lkt.js +2 -1
  124. package/dist/locale-data/ln.js +5 -1
  125. package/dist/locale-data/lo.js +2 -1
  126. package/dist/locale-data/lt.js +2 -1
  127. package/dist/locale-data/lu.js +2 -0
  128. package/dist/locale-data/luo.js +2 -0
  129. package/dist/locale-data/luy.js +2 -0
  130. package/dist/locale-data/lv.js +2 -1
  131. package/dist/locale-data/mas.js +3 -1
  132. package/dist/locale-data/mer.js +2 -0
  133. package/dist/locale-data/mfe.js +2 -0
  134. package/dist/locale-data/mg.js +2 -1
  135. package/dist/locale-data/mgh.js +2 -0
  136. package/dist/locale-data/mgo.js +2 -1
  137. package/dist/locale-data/mk.js +2 -1
  138. package/dist/locale-data/ml.js +2 -1
  139. package/dist/locale-data/mn.js +4 -1
  140. package/dist/locale-data/mo.js +1 -0
  141. package/dist/locale-data/mr.js +2 -1
  142. package/dist/locale-data/ms.js +6 -1
  143. package/dist/locale-data/mt.js +2 -1
  144. package/dist/locale-data/mua.js +2 -0
  145. package/dist/locale-data/my.js +2 -1
  146. package/dist/locale-data/nah.js +1 -0
  147. package/dist/locale-data/naq.js +2 -1
  148. package/dist/locale-data/nb.js +3 -1
  149. package/dist/locale-data/nd.js +2 -1
  150. package/dist/locale-data/ne.js +3 -1
  151. package/dist/locale-data/nl.js +8 -1
  152. package/dist/locale-data/nmg.js +2 -0
  153. package/dist/locale-data/nn.js +2 -1
  154. package/dist/locale-data/nnh.js +2 -1
  155. package/dist/locale-data/no.js +1 -0
  156. package/dist/locale-data/nqo.js +1 -0
  157. package/dist/locale-data/nr.js +2 -1
  158. package/dist/locale-data/nso.js +2 -1
  159. package/dist/locale-data/nus.js +2 -0
  160. package/dist/locale-data/ny.js +1 -0
  161. package/dist/locale-data/nyn.js +2 -1
  162. package/dist/locale-data/om.js +3 -1
  163. package/dist/locale-data/or.js +2 -1
  164. package/dist/locale-data/os.js +3 -1
  165. package/dist/locale-data/pa.js +5 -1
  166. package/dist/locale-data/pap.js +1 -0
  167. package/dist/locale-data/pl.js +2 -1
  168. package/dist/locale-data/prg.js +1 -0
  169. package/dist/locale-data/ps.js +2 -1
  170. package/dist/locale-data/pt.js +10 -1
  171. package/dist/locale-data/qu.js +4 -0
  172. package/dist/locale-data/rm.js +2 -1
  173. package/dist/locale-data/rn.js +2 -0
  174. package/dist/locale-data/ro.js +3 -1
  175. package/dist/locale-data/rof.js +2 -1
  176. package/dist/locale-data/ru.js +7 -1
  177. package/dist/locale-data/rw.js +2 -0
  178. package/dist/locale-data/rwk.js +2 -1
  179. package/dist/locale-data/sah.js +2 -1
  180. package/dist/locale-data/saq.js +2 -1
  181. package/dist/locale-data/sbp.js +2 -0
  182. package/dist/locale-data/se.js +4 -1
  183. package/dist/locale-data/seh.js +2 -1
  184. package/dist/locale-data/ses.js +2 -1
  185. package/dist/locale-data/sg.js +2 -1
  186. package/dist/locale-data/sh.js +1 -0
  187. package/dist/locale-data/shi.js +5 -1
  188. package/dist/locale-data/si.js +2 -1
  189. package/dist/locale-data/sk.js +2 -1
  190. package/dist/locale-data/sl.js +2 -1
  191. package/dist/locale-data/sma.js +1 -0
  192. package/dist/locale-data/smi.js +1 -0
  193. package/dist/locale-data/smj.js +1 -0
  194. package/dist/locale-data/smn.js +2 -0
  195. package/dist/locale-data/sms.js +1 -0
  196. package/dist/locale-data/sn.js +2 -1
  197. package/dist/locale-data/so.js +5 -1
  198. package/dist/locale-data/sq.js +4 -1
  199. package/dist/locale-data/sr.js +11 -1
  200. package/dist/locale-data/ss.js +3 -1
  201. package/dist/locale-data/ssy.js +2 -1
  202. package/dist/locale-data/st.js +1 -1
  203. package/dist/locale-data/sv.js +4 -1
  204. package/dist/locale-data/sw.js +4 -1
  205. package/dist/locale-data/swc.js +2 -0
  206. package/dist/locale-data/syr.js +1 -0
  207. package/dist/locale-data/ta.js +5 -1
  208. package/dist/locale-data/te.js +2 -1
  209. package/dist/locale-data/teo.js +3 -1
  210. package/dist/locale-data/th.js +2 -1
  211. package/dist/locale-data/ti.js +3 -1
  212. package/dist/locale-data/tig.js +1 -1
  213. package/dist/locale-data/tk.js +1 -0
  214. package/dist/locale-data/tl.js +1 -0
  215. package/dist/locale-data/tn.js +3 -1
  216. package/dist/locale-data/to.js +2 -1
  217. package/dist/locale-data/tr.js +3 -1
  218. package/dist/locale-data/ts.js +2 -1
  219. package/dist/locale-data/twq.js +2 -0
  220. package/dist/locale-data/tzm.js +3 -1
  221. package/dist/locale-data/ug.js +3 -1
  222. package/dist/locale-data/uk.js +2 -1
  223. package/dist/locale-data/ur.js +3 -1
  224. package/dist/locale-data/uz.js +7 -1
  225. package/dist/locale-data/vai.js +5 -0
  226. package/dist/locale-data/ve.js +2 -1
  227. package/dist/locale-data/vi.js +2 -1
  228. package/dist/locale-data/vo.js +2 -1
  229. package/dist/locale-data/vun.js +2 -1
  230. package/dist/locale-data/wa.js +1 -0
  231. package/dist/locale-data/wae.js +2 -1
  232. package/dist/locale-data/wo.js +1 -0
  233. package/dist/locale-data/xh.js +1 -1
  234. package/dist/locale-data/xog.js +2 -1
  235. package/dist/locale-data/yav.js +2 -0
  236. package/dist/locale-data/yi.js +2 -0
  237. package/dist/locale-data/yo.js +3 -1
  238. package/dist/locale-data/zgh.js +2 -0
  239. package/dist/locale-data/zh.js +10 -1
  240. package/dist/locale-data/zu.js +2 -1
  241. package/index.js +4 -6
  242. package/lib/compiler.js +21 -21
  243. package/lib/core.js +54 -46
  244. package/lib/en.js +2 -12
  245. package/lib/es5.js +8 -18
  246. package/lib/locales.js +752 -161
  247. package/lib/main.js +5 -14
  248. package/lib/utils.js +9 -18
  249. package/package.json +18 -12
  250. package/src/compiler.js +13 -10
  251. package/src/core.js +44 -33
  252. package/src/en.js +1 -1
  253. package/bower.json +0 -40
package/README.md CHANGED
@@ -7,8 +7,8 @@ Formats ICU Message strings with number, date, plural, and select placeholders t
7
7
  [![Build Status][travis-badge]][travis]
8
8
  [![Dependency Status][david-badge]][david]
9
9
 
10
+ [![Sauce Test Status][sauce-badge]][sauce]
10
11
 
11
- [![Sauce Test Status](https://saucelabs.com/browser-matrix/intl-messageformat.svg)](https://saucelabs.com/u/intl-messageformat)
12
12
 
13
13
  Overview
14
14
  --------
@@ -29,7 +29,7 @@ Messages are provided into the constructor as a `String` message, or a [pre-pars
29
29
  var msg = new IntlMessageFormat(message, locales, [formats]);
30
30
  ```
31
31
 
32
- The string `message` is parsed, then stored internally in a compiled form that is optimized for the `format()` method to produce the formatted string for display to the user.
32
+ The string `message` is parsed, then stored internally in a compiled form that is optimized for the `format()` method to produce the formatted string for displaying to the user.
33
33
 
34
34
  ```js
35
35
  var output = msg.format(values);
@@ -37,7 +37,7 @@ var output = msg.format(values);
37
37
 
38
38
  ### Common Usage Example
39
39
 
40
- A very common example is formatting messages that have numbers with plural lables. With this package you can make sure that the string is properly formatted for a person's locale, e.g.:
40
+ A very common example is formatting messages that have numbers with plural labels. With this package you can make sure that the string is properly formatted for a person's locale, e.g.:
41
41
 
42
42
  ```js
43
43
  var MESSAGES = {
@@ -75,7 +75,7 @@ The message syntax that this package uses is not proprietary, in fact it's a com
75
75
 
76
76
  * Uses industry standards: [ICU Message syntax][ICU] and [CLDR locale data][CLDR].
77
77
 
78
- * Supports **plural** and **select** message arguments.
78
+ * Supports **plural**, **select**, and **selectordinal** message arguments.
79
79
 
80
80
  * Formats numbers and dates/times in messages using [`Intl.NumberFormat`][Intl-NF] and [`Intl.DateTimeFormat`][Intl-DTF], respectively.
81
81
 
@@ -124,21 +124,13 @@ _Note: When using the Intl.js Polyfill in Node.js, it will automatically load th
124
124
  <script src="intl-messageformat/intl-messageformat.min.js"></script>
125
125
  ```
126
126
 
127
- By default, Intl MessageFormat ships with the locale data for English built-in to the runtime library. When you need to format data in another locale, include its data; e.g., for French:
127
+ By default, Intl MessageFormat ships with the locale data for English (`en`) built-in to the library's runtime. When you need to format data in another locale, include its data; e.g., for French:
128
128
 
129
129
  ```html
130
130
  <script src="intl-messageformat/locale-data/fr.js"></script>
131
131
  ```
132
132
 
133
- _Note: All 150+ locales supported by this package use their root BCP 47 langage tag; i.e., the part before the first hyphen (if any)._
134
-
135
- #### Using Raw Git CDN
136
-
137
- If you'd like to load this package via a CDN, instead of hosting it yourself, one option is using [Raw Git][rawgit]. **Be sure to reference a `dist/` file using a Git tag:**
138
-
139
- ```html
140
- <script src="https://cdn.rawgit.com/yahoo/intl-messageformat/v1.0.1/dist/intl-messageformat.min.js"></script>
141
- ```
133
+ _Note: All 200+ languages supported by this package use their root BCP 47 language tag; i.e., the part before the first hyphen (if any)._
142
134
 
143
135
  ### Loading Intl MessageFormat in Node.js
144
136
 
@@ -148,7 +140,7 @@ Simply `require()` this package:
148
140
  var IntlMessageFormat = require('intl-messageformat');
149
141
  ```
150
142
 
151
- _Note: in Node.js, the data for all 150+ locales is loaded along with the library._
143
+ _Note: in Node.js, the data for all 200+ languages is loaded along with the library._
152
144
 
153
145
  ### Public API
154
146
 
@@ -157,7 +149,7 @@ To create a message to format, use the `IntlMessageFormat` constructor. The cons
157
149
 
158
150
  - **message** - _{String | AST}_ - String message (or pre-parsed AST) that serves as formatting pattern.
159
151
 
160
- - **locales** - _{String | String[]}_ - A string with a BCP 47 language tag, or an array of such strings. If you do not provide a locale, the default locale will be used, but you should _always_ provide one!
152
+ - **locales** - _{String | String[]}_ - A string with a BCP 47 language tag, or an array of such strings. If you do not provide a locale, the default locale will be used. When an array of locales is provided, each item and its ancestor locales are checked and the first one with registered locale data is returned. **See: [Locale Resolution](#locale-resolution) for more details.**
161
153
 
162
154
  - **[formats]** - _{Object}_ - Optional object with user defined options for format styles.
163
155
 
@@ -165,6 +157,38 @@ To create a message to format, use the `IntlMessageFormat` constructor. The cons
165
157
  var msg = new IntlMessageFormat('My name is {name}.', 'en-US');
166
158
  ```
167
159
 
160
+ #### Locale Resolution
161
+
162
+ `IntlMessageFormat` uses a locale resolution process similar to that of the built-in `Intl` APIs to determine which locale data to use based on the `locales` value passed to the constructor. The result of this resolution process can be determined by call the `resolvedOptions()` prototype method.
163
+
164
+ The following are the abstract steps `IntlMessageFormat` goes through to resolve the locale value:
165
+
166
+ * If no extra locale data is loaded, the locale will _always_ resolved to `"en"`.
167
+
168
+ * If locale data is missing for a leaf locale like `"fr-FR"`, but there _is_ data for one of its ancestors, `"fr"` in this case, then its ancestor will be used.
169
+
170
+ * If there's data for the specified locale, then that locale will be resolved; i.e.,
171
+
172
+ ```js
173
+ var mf = new IntlMessageFormat('', 'en-US');
174
+ assert(mf.resolvedOptions().locale === 'en-US'); // true
175
+ ```
176
+
177
+ * The resolved locales are now normalized; e.g., `"en-us"` will resolve to: `"en-US"`.
178
+
179
+ _Note: When an array is provided for `locales`, the above steps happen for each item in that array until a match is found._
180
+
181
+ #### `resolvedOptions()` Method
182
+
183
+ This method returns an object with the options values that were resolved during instance creation. It currently only contains a `locale` property; here's an example:
184
+
185
+ ```js
186
+ var msg = new IntlMessageFormat('', 'en-us');
187
+ console.log(msg.resolvedOptions().locale); // => "en-US"
188
+ ```
189
+
190
+ Notice how the specified locale was the all lower-case value: `"en-us"`, but it was resolved and normalized to: `"en-US"`.
191
+
168
192
  #### `format(values)` Method
169
193
 
170
194
  Once the message is created, formatting the message is done by calling the `format()` method on the instance and passing a collection of `values`:
@@ -174,7 +198,7 @@ var output = msg.format({name: "Eric"});
174
198
  console.log(output); // => "My name is Eric."
175
199
  ```
176
200
 
177
- **Note:** A value _must_ be supplied for every argument in the message pattern the instance was constructed with.
201
+ _Note: A value **must** be supplied for every argument in the message pattern the instance was constructed with._
178
202
 
179
203
  #### User Defined Formats
180
204
 
@@ -225,7 +249,7 @@ console.log(msg.format({numPhotos: 1})); // => "You have one photo."
225
249
  console.log(msg.format({numPhotos: 1000})); // => "You have 1,000 photos."
226
250
  ```
227
251
 
228
- _Note how when `numPhotos` was `1000`, the number is formatted with the correct thousands separator._
252
+ _Note: how when `numPhotos` was `1000`, the number is formatted with the correct thousands separator._
229
253
 
230
254
 
231
255
  License
@@ -241,6 +265,8 @@ See the [LICENSE file][LICENSE] for license text and copyright information.
241
265
  [david-badge]: https://img.shields.io/david/yahoo/intl-messageformat.svg?style=flat-square
242
266
  [travis]: https://travis-ci.org/yahoo/intl-messageformat
243
267
  [travis-badge]: https://img.shields.io/travis/yahoo/intl-messageformat.svg?style=flat-square
268
+ [sauce]: https://saucelabs.com/u/intl-messageformat
269
+ [sauce-badge]: https://saucelabs.com/browser-matrix/intl-messageformat.svg
244
270
  [strawman]: http://wiki.ecmascript.org/doku.php?id=globalization:messageformatting
245
271
  [parser]: https://github.com/yahoo/intl-messageformat-parser
246
272
  [ICU]: http://userguide.icu-project.org/formatparse/messages