react-intl 2.2.1 → 2.4.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 (262) hide show
  1. package/CONTRIBUTING.md +20 -0
  2. package/dist/react-intl.js +1017 -1475
  3. package/dist/react-intl.js.map +1 -1
  4. package/dist/react-intl.min.js +1 -2
  5. package/dist/react-intl.min.js.map +1 -1
  6. package/lib/index.es.js +983 -1428
  7. package/lib/index.js +990 -1435
  8. package/locale-data/af.js +1 -1
  9. package/locale-data/agq.js +1 -1
  10. package/locale-data/ak.js +1 -1
  11. package/locale-data/am.js +1 -1
  12. package/locale-data/ar.js +1 -1
  13. package/locale-data/ars.js +1 -0
  14. package/locale-data/as.js +1 -1
  15. package/locale-data/asa.js +1 -1
  16. package/locale-data/ast.js +1 -1
  17. package/locale-data/az.js +1 -1
  18. package/locale-data/bas.js +1 -1
  19. package/locale-data/be.js +1 -1
  20. package/locale-data/bem.js +1 -1
  21. package/locale-data/bez.js +1 -1
  22. package/locale-data/bg.js +1 -1
  23. package/locale-data/bh.js +1 -1
  24. package/locale-data/bm.js +1 -1
  25. package/locale-data/bn.js +1 -1
  26. package/locale-data/bo.js +1 -1
  27. package/locale-data/br.js +1 -1
  28. package/locale-data/brx.js +1 -1
  29. package/locale-data/bs.js +1 -1
  30. package/locale-data/ca.js +1 -1
  31. package/locale-data/ce.js +1 -1
  32. package/locale-data/cgg.js +1 -1
  33. package/locale-data/chr.js +1 -1
  34. package/locale-data/ckb.js +1 -1
  35. package/locale-data/cs.js +1 -1
  36. package/locale-data/cu.js +1 -1
  37. package/locale-data/cy.js +1 -1
  38. package/locale-data/da.js +1 -1
  39. package/locale-data/dav.js +1 -1
  40. package/locale-data/de.js +1 -1
  41. package/locale-data/dje.js +1 -1
  42. package/locale-data/dsb.js +1 -1
  43. package/locale-data/dua.js +1 -1
  44. package/locale-data/dv.js +1 -1
  45. package/locale-data/dyo.js +1 -1
  46. package/locale-data/dz.js +1 -1
  47. package/locale-data/ebu.js +1 -1
  48. package/locale-data/ee.js +1 -1
  49. package/locale-data/el.js +1 -1
  50. package/locale-data/en.js +1 -1
  51. package/locale-data/eo.js +1 -1
  52. package/locale-data/es.js +1 -1
  53. package/locale-data/et.js +1 -1
  54. package/locale-data/eu.js +1 -1
  55. package/locale-data/ewo.js +1 -1
  56. package/locale-data/fa.js +1 -1
  57. package/locale-data/ff.js +1 -1
  58. package/locale-data/fi.js +1 -1
  59. package/locale-data/fil.js +1 -1
  60. package/locale-data/fo.js +1 -1
  61. package/locale-data/fr.js +1 -1
  62. package/locale-data/fur.js +1 -1
  63. package/locale-data/fy.js +1 -1
  64. package/locale-data/ga.js +1 -1
  65. package/locale-data/gd.js +1 -1
  66. package/locale-data/gl.js +1 -1
  67. package/locale-data/gsw.js +1 -1
  68. package/locale-data/gu.js +1 -1
  69. package/locale-data/guw.js +1 -1
  70. package/locale-data/guz.js +1 -1
  71. package/locale-data/gv.js +1 -1
  72. package/locale-data/ha.js +1 -1
  73. package/locale-data/haw.js +1 -1
  74. package/locale-data/he.js +1 -1
  75. package/locale-data/hi.js +1 -1
  76. package/locale-data/hr.js +1 -1
  77. package/locale-data/hsb.js +1 -1
  78. package/locale-data/hu.js +1 -1
  79. package/locale-data/hy.js +1 -1
  80. package/locale-data/id.js +1 -1
  81. package/locale-data/ig.js +1 -1
  82. package/locale-data/ii.js +1 -1
  83. package/locale-data/in.js +1 -1
  84. package/locale-data/index.js +1 -10
  85. package/locale-data/is.js +1 -1
  86. package/locale-data/it.js +1 -1
  87. package/locale-data/iu.js +1 -1
  88. package/locale-data/iw.js +1 -1
  89. package/locale-data/ja.js +1 -1
  90. package/locale-data/jbo.js +1 -1
  91. package/locale-data/jgo.js +1 -1
  92. package/locale-data/ji.js +1 -1
  93. package/locale-data/jmc.js +1 -1
  94. package/locale-data/jv.js +1 -1
  95. package/locale-data/jw.js +1 -1
  96. package/locale-data/ka.js +1 -1
  97. package/locale-data/kab.js +1 -1
  98. package/locale-data/kaj.js +1 -1
  99. package/locale-data/kam.js +1 -1
  100. package/locale-data/kcg.js +1 -1
  101. package/locale-data/kde.js +1 -1
  102. package/locale-data/kea.js +1 -1
  103. package/locale-data/khq.js +1 -1
  104. package/locale-data/ki.js +1 -1
  105. package/locale-data/kk.js +1 -1
  106. package/locale-data/kkj.js +1 -1
  107. package/locale-data/kl.js +1 -1
  108. package/locale-data/kln.js +1 -1
  109. package/locale-data/km.js +1 -1
  110. package/locale-data/kn.js +1 -1
  111. package/locale-data/ko.js +1 -1
  112. package/locale-data/kok.js +1 -1
  113. package/locale-data/ks.js +1 -1
  114. package/locale-data/ksb.js +1 -1
  115. package/locale-data/ksf.js +1 -1
  116. package/locale-data/ksh.js +1 -1
  117. package/locale-data/ku.js +1 -1
  118. package/locale-data/kw.js +1 -1
  119. package/locale-data/ky.js +1 -1
  120. package/locale-data/lag.js +1 -1
  121. package/locale-data/lb.js +1 -1
  122. package/locale-data/lg.js +1 -1
  123. package/locale-data/lkt.js +1 -1
  124. package/locale-data/ln.js +1 -1
  125. package/locale-data/lo.js +1 -1
  126. package/locale-data/lrc.js +1 -1
  127. package/locale-data/lt.js +1 -1
  128. package/locale-data/lu.js +1 -1
  129. package/locale-data/luo.js +1 -1
  130. package/locale-data/luy.js +1 -1
  131. package/locale-data/lv.js +1 -1
  132. package/locale-data/mas.js +1 -1
  133. package/locale-data/mer.js +1 -1
  134. package/locale-data/mfe.js +1 -1
  135. package/locale-data/mg.js +1 -1
  136. package/locale-data/mgh.js +1 -1
  137. package/locale-data/mgo.js +1 -1
  138. package/locale-data/mk.js +1 -1
  139. package/locale-data/ml.js +1 -1
  140. package/locale-data/mn.js +1 -1
  141. package/locale-data/mo.js +1 -1
  142. package/locale-data/mr.js +1 -1
  143. package/locale-data/ms.js +1 -1
  144. package/locale-data/mt.js +1 -1
  145. package/locale-data/mua.js +1 -1
  146. package/locale-data/my.js +1 -1
  147. package/locale-data/mzn.js +1 -1
  148. package/locale-data/nah.js +1 -1
  149. package/locale-data/naq.js +1 -1
  150. package/locale-data/nb.js +1 -1
  151. package/locale-data/nd.js +1 -1
  152. package/locale-data/nds.js +1 -0
  153. package/locale-data/ne.js +1 -1
  154. package/locale-data/nl.js +1 -1
  155. package/locale-data/nmg.js +1 -1
  156. package/locale-data/nn.js +1 -1
  157. package/locale-data/nnh.js +1 -1
  158. package/locale-data/no.js +1 -1
  159. package/locale-data/nqo.js +1 -1
  160. package/locale-data/nr.js +1 -1
  161. package/locale-data/nso.js +1 -1
  162. package/locale-data/nus.js +1 -1
  163. package/locale-data/ny.js +1 -1
  164. package/locale-data/nyn.js +1 -1
  165. package/locale-data/om.js +1 -1
  166. package/locale-data/or.js +1 -1
  167. package/locale-data/os.js +1 -1
  168. package/locale-data/pa.js +1 -1
  169. package/locale-data/pap.js +1 -1
  170. package/locale-data/pl.js +1 -1
  171. package/locale-data/prg.js +1 -1
  172. package/locale-data/ps.js +1 -1
  173. package/locale-data/pt.js +1 -1
  174. package/locale-data/qu.js +1 -1
  175. package/locale-data/rm.js +1 -1
  176. package/locale-data/rn.js +1 -1
  177. package/locale-data/ro.js +1 -1
  178. package/locale-data/rof.js +1 -1
  179. package/locale-data/ru.js +1 -1
  180. package/locale-data/rw.js +1 -1
  181. package/locale-data/rwk.js +1 -1
  182. package/locale-data/sah.js +1 -1
  183. package/locale-data/saq.js +1 -1
  184. package/locale-data/sbp.js +1 -1
  185. package/locale-data/sdh.js +1 -1
  186. package/locale-data/se.js +1 -1
  187. package/locale-data/seh.js +1 -1
  188. package/locale-data/ses.js +1 -1
  189. package/locale-data/sg.js +1 -1
  190. package/locale-data/sh.js +1 -1
  191. package/locale-data/shi.js +1 -1
  192. package/locale-data/si.js +1 -1
  193. package/locale-data/sk.js +1 -1
  194. package/locale-data/sl.js +1 -1
  195. package/locale-data/sma.js +1 -1
  196. package/locale-data/smi.js +1 -1
  197. package/locale-data/smj.js +1 -1
  198. package/locale-data/smn.js +1 -1
  199. package/locale-data/sms.js +1 -1
  200. package/locale-data/sn.js +1 -1
  201. package/locale-data/so.js +1 -1
  202. package/locale-data/sq.js +1 -1
  203. package/locale-data/sr.js +1 -1
  204. package/locale-data/ss.js +1 -1
  205. package/locale-data/ssy.js +1 -1
  206. package/locale-data/st.js +1 -1
  207. package/locale-data/sv.js +1 -1
  208. package/locale-data/sw.js +1 -1
  209. package/locale-data/syr.js +1 -1
  210. package/locale-data/ta.js +1 -1
  211. package/locale-data/te.js +1 -1
  212. package/locale-data/teo.js +1 -1
  213. package/locale-data/th.js +1 -1
  214. package/locale-data/ti.js +1 -1
  215. package/locale-data/tig.js +1 -1
  216. package/locale-data/tk.js +1 -1
  217. package/locale-data/tl.js +1 -1
  218. package/locale-data/tn.js +1 -1
  219. package/locale-data/to.js +1 -1
  220. package/locale-data/tr.js +1 -1
  221. package/locale-data/ts.js +1 -1
  222. package/locale-data/twq.js +1 -1
  223. package/locale-data/tzm.js +1 -1
  224. package/locale-data/ug.js +1 -1
  225. package/locale-data/uk.js +1 -1
  226. package/locale-data/ur.js +1 -1
  227. package/locale-data/uz.js +1 -1
  228. package/locale-data/vai.js +1 -1
  229. package/locale-data/ve.js +1 -1
  230. package/locale-data/vi.js +1 -1
  231. package/locale-data/vo.js +1 -1
  232. package/locale-data/vun.js +1 -1
  233. package/locale-data/wa.js +1 -1
  234. package/locale-data/wae.js +1 -1
  235. package/locale-data/wo.js +1 -1
  236. package/locale-data/xh.js +1 -1
  237. package/locale-data/xog.js +1 -1
  238. package/locale-data/yav.js +1 -1
  239. package/locale-data/yi.js +1 -1
  240. package/locale-data/yo.js +1 -1
  241. package/locale-data/yue.js +1 -0
  242. package/locale-data/zgh.js +1 -1
  243. package/locale-data/zh.js +1 -1
  244. package/locale-data/zu.js +1 -1
  245. package/package.json +33 -27
  246. package/src/components/date.js +30 -29
  247. package/src/components/html-message.js +63 -62
  248. package/src/components/message.js +117 -114
  249. package/src/components/number.js +30 -29
  250. package/src/components/plural.js +37 -36
  251. package/src/components/provider.js +135 -134
  252. package/src/components/relative.js +128 -120
  253. package/src/components/time.js +30 -29
  254. package/src/define-messages.js +3 -3
  255. package/src/en.js +1 -1
  256. package/src/format.js +209 -208
  257. package/src/inject.js +38 -40
  258. package/src/locale-data-registry.js +21 -21
  259. package/src/plural.js +9 -9
  260. package/src/types.js +58 -48
  261. package/src/utils.js +65 -55
  262. package/yarn.lock +4832 -0
package/src/plural.js CHANGED
@@ -9,20 +9,20 @@
9
9
  import IntlMessageFormat from 'intl-messageformat';
10
10
 
11
11
  function resolveLocale(locales) {
12
- // IntlMessageFormat#_resolveLocale() does not depend on `this`.
13
- return IntlMessageFormat.prototype._resolveLocale(locales);
12
+ // IntlMessageFormat#_resolveLocale() does not depend on `this`.
13
+ return IntlMessageFormat.prototype._resolveLocale(locales);
14
14
  }
15
15
 
16
16
  function findPluralFunction(locale) {
17
- // IntlMessageFormat#_findPluralFunction() does not depend on `this`.
18
- return IntlMessageFormat.prototype._findPluralRuleFunction(locale);
17
+ // IntlMessageFormat#_findPluralFunction() does not depend on `this`.
18
+ return IntlMessageFormat.prototype._findPluralRuleFunction(locale);
19
19
  }
20
20
 
21
21
  export default class IntlPluralFormat {
22
- constructor(locales, options = {}) {
23
- let useOrdinal = options.style === 'ordinal';
24
- let pluralFn = findPluralFunction(resolveLocale(locales));
22
+ constructor(locales, options = {}) {
23
+ let useOrdinal = options.style === 'ordinal';
24
+ let pluralFn = findPluralFunction(resolveLocale(locales));
25
25
 
26
- this.format = (value) => pluralFn(value, useOrdinal);
27
- }
26
+ this.format = value => pluralFn(value, useOrdinal);
27
+ }
28
28
  }
package/src/types.js CHANGED
@@ -4,85 +4,95 @@
4
4
  * See the accompanying LICENSE file for terms.
5
5
  */
6
6
 
7
- import {PropTypes} from 'react';
7
+ import PropTypes from 'prop-types';
8
8
 
9
- const {bool, number, string, func, object, oneOf, shape, any} = PropTypes;
9
+ const {
10
+ bool,
11
+ number,
12
+ string,
13
+ func,
14
+ object,
15
+ oneOf,
16
+ shape,
17
+ any,
18
+ oneOfType,
19
+ } = PropTypes;
10
20
  const localeMatcher = oneOf(['best fit', 'lookup']);
11
21
  const narrowShortLong = oneOf(['narrow', 'short', 'long']);
12
22
  const numeric2digit = oneOf(['numeric', '2-digit']);
13
23
  const funcReq = func.isRequired;
14
24
 
15
25
  export const intlConfigPropTypes = {
16
- locale : string,
17
- formats : object,
18
- messages : object,
19
- textComponent: any,
26
+ locale: string,
27
+ formats: object,
28
+ messages: object,
29
+ textComponent: any,
20
30
 
21
- defaultLocale : string,
22
- defaultFormats: object,
31
+ defaultLocale: string,
32
+ defaultFormats: object,
23
33
  };
24
34
 
25
35
  export const intlFormatPropTypes = {
26
- formatDate : funcReq,
27
- formatTime : funcReq,
28
- formatRelative : funcReq,
29
- formatNumber : funcReq,
30
- formatPlural : funcReq,
31
- formatMessage : funcReq,
32
- formatHTMLMessage: funcReq,
36
+ formatDate: funcReq,
37
+ formatTime: funcReq,
38
+ formatRelative: funcReq,
39
+ formatNumber: funcReq,
40
+ formatPlural: funcReq,
41
+ formatMessage: funcReq,
42
+ formatHTMLMessage: funcReq,
33
43
  };
34
44
 
35
45
  export const intlShape = shape({
36
- ...intlConfigPropTypes,
37
- ...intlFormatPropTypes,
38
- formatters: object,
39
- now: funcReq,
46
+ ...intlConfigPropTypes,
47
+ ...intlFormatPropTypes,
48
+ formatters: object,
49
+ now: funcReq,
40
50
  });
41
51
 
42
52
  export const messageDescriptorPropTypes = {
43
- id : string.isRequired,
44
- description : string,
45
- defaultMessage: string,
53
+ id: string.isRequired,
54
+ description: oneOfType([string, object]),
55
+ defaultMessage: string,
46
56
  };
47
57
 
48
58
  export const dateTimeFormatPropTypes = {
49
- localeMatcher,
50
- formatMatcher: oneOf(['basic', 'best fit']),
59
+ localeMatcher,
60
+ formatMatcher: oneOf(['basic', 'best fit']),
51
61
 
52
- timeZone: string,
53
- hour12 : bool,
62
+ timeZone: string,
63
+ hour12: bool,
54
64
 
55
- weekday : narrowShortLong,
56
- era : narrowShortLong,
57
- year : numeric2digit,
58
- month : oneOf(['numeric', '2-digit', 'narrow', 'short', 'long']),
59
- day : numeric2digit,
60
- hour : numeric2digit,
61
- minute : numeric2digit,
62
- second : numeric2digit,
63
- timeZoneName: oneOf(['short', 'long']),
65
+ weekday: narrowShortLong,
66
+ era: narrowShortLong,
67
+ year: numeric2digit,
68
+ month: oneOf(['numeric', '2-digit', 'narrow', 'short', 'long']),
69
+ day: numeric2digit,
70
+ hour: numeric2digit,
71
+ minute: numeric2digit,
72
+ second: numeric2digit,
73
+ timeZoneName: oneOf(['short', 'long']),
64
74
  };
65
75
 
66
76
  export const numberFormatPropTypes = {
67
- localeMatcher,
77
+ localeMatcher,
68
78
 
69
- style : oneOf(['decimal', 'currency', 'percent']),
70
- currency : string,
71
- currencyDisplay: oneOf(['symbol', 'code', 'name']),
72
- useGrouping : bool,
79
+ style: oneOf(['decimal', 'currency', 'percent']),
80
+ currency: string,
81
+ currencyDisplay: oneOf(['symbol', 'code', 'name']),
82
+ useGrouping: bool,
73
83
 
74
- minimumIntegerDigits : number,
75
- minimumFractionDigits : number,
76
- maximumFractionDigits : number,
77
- minimumSignificantDigits: number,
78
- maximumSignificantDigits: number,
84
+ minimumIntegerDigits: number,
85
+ minimumFractionDigits: number,
86
+ maximumFractionDigits: number,
87
+ minimumSignificantDigits: number,
88
+ maximumSignificantDigits: number,
79
89
  };
80
90
 
81
91
  export const relativeFormatPropTypes = {
82
- style: oneOf(['best fit', 'numeric']),
83
- units: oneOf(['second', 'minute', 'hour', 'day', 'month', 'year']),
92
+ style: oneOf(['best fit', 'numeric']),
93
+ units: oneOf(['second', 'minute', 'hour', 'day', 'month', 'year']),
84
94
  };
85
95
 
86
96
  export const pluralFormatPropTypes = {
87
- style: oneOf(['cardinal', 'ordinal']),
97
+ style: oneOf(['cardinal', 'ordinal']),
88
98
  };
package/src/utils.js CHANGED
@@ -15,79 +15,89 @@ import {intlConfigPropTypes} from './types';
15
15
  const intlConfigPropNames = Object.keys(intlConfigPropTypes);
16
16
 
17
17
  const ESCAPED_CHARS = {
18
- '&' : '&',
19
- '>' : '>',
20
- '<' : '&lt;',
21
- '"' : '&quot;',
22
- '\'': '&#x27;',
18
+ '&': '&amp;',
19
+ '>': '&gt;',
20
+ '<': '&lt;',
21
+ '"': '&quot;',
22
+ "'": '&#x27;',
23
23
  };
24
24
 
25
25
  const UNSAFE_CHARS_REGEX = /[&><"']/g;
26
26
 
27
27
  export function escape(str) {
28
- return ('' + str).replace(UNSAFE_CHARS_REGEX, (match) => ESCAPED_CHARS[match]);
28
+ return ('' + str).replace(UNSAFE_CHARS_REGEX, match => ESCAPED_CHARS[match]);
29
29
  }
30
30
 
31
31
  export function filterProps(props, whitelist, defaults = {}) {
32
- return whitelist.reduce((filtered, name) => {
33
- if (props.hasOwnProperty(name)) {
34
- filtered[name] = props[name];
35
- } else if (defaults.hasOwnProperty(name)) {
36
- filtered[name] = defaults[name];
37
- }
38
-
39
- return filtered;
40
- }, {});
32
+ return whitelist.reduce((filtered, name) => {
33
+ if (props.hasOwnProperty(name)) {
34
+ filtered[name] = props[name];
35
+ } else if (defaults.hasOwnProperty(name)) {
36
+ filtered[name] = defaults[name];
37
+ }
38
+
39
+ return filtered;
40
+ }, {});
41
41
  }
42
42
 
43
43
  export function invariantIntlContext({intl} = {}) {
44
- invariant(intl,
45
- '[React Intl] Could not find required `intl` object. ' +
46
- '<IntlProvider> needs to exist in the component ancestry.'
47
- );
44
+ invariant(
45
+ intl,
46
+ '[React Intl] Could not find required `intl` object. ' +
47
+ '<IntlProvider> needs to exist in the component ancestry.'
48
+ );
48
49
  }
49
50
 
50
51
  export function shallowEquals(objA, objB) {
51
- if (objA === objB) {
52
- return true;
53
- }
54
-
55
- if (typeof objA !== 'object' || objA === null ||
56
- typeof objB !== 'object' || objB === null) {
57
- return false;
58
- }
59
-
60
- let keysA = Object.keys(objA);
61
- let keysB = Object.keys(objB);
62
-
63
- if (keysA.length !== keysB.length) {
64
- return false;
65
- }
66
-
67
- // Test for A's keys different from B.
68
- let bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB);
69
- for (let i = 0; i < keysA.length; i++) {
70
- if (!bHasOwnProperty(keysA[i]) || objA[keysA[i]] !== objB[keysA[i]]) {
71
- return false;
72
- }
52
+ if (objA === objB) {
53
+ return true;
54
+ }
55
+
56
+ if (
57
+ typeof objA !== 'object' ||
58
+ objA === null ||
59
+ typeof objB !== 'object' ||
60
+ objB === null
61
+ ) {
62
+ return false;
63
+ }
64
+
65
+ let keysA = Object.keys(objA);
66
+ let keysB = Object.keys(objB);
67
+
68
+ if (keysA.length !== keysB.length) {
69
+ return false;
70
+ }
71
+
72
+ // Test for A's keys different from B.
73
+ let bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB);
74
+ for (let i = 0; i < keysA.length; i++) {
75
+ if (!bHasOwnProperty(keysA[i]) || objA[keysA[i]] !== objB[keysA[i]]) {
76
+ return false;
73
77
  }
78
+ }
74
79
 
75
- return true;
80
+ return true;
76
81
  }
77
82
 
78
83
  export function shouldIntlComponentUpdate(
79
- {props, state, context = {}},
80
- nextProps, nextState, nextContext = {}
84
+ {props, state, context = {}},
85
+ nextProps,
86
+ nextState,
87
+ nextContext = {}
81
88
  ) {
82
- const {intl = {}} = context;
83
- const {intl: nextIntl = {}} = nextContext;
84
-
85
- return (
86
- !shallowEquals(nextProps, props) ||
87
- !shallowEquals(nextState, state) ||
88
- !(nextIntl === intl || shallowEquals(
89
- filterProps(nextIntl, intlConfigPropNames),
90
- filterProps(intl, intlConfigPropNames)
91
- ))
92
- );
89
+ const {intl = {}} = context;
90
+ const {intl: nextIntl = {}} = nextContext;
91
+
92
+ return (
93
+ !shallowEquals(nextProps, props) ||
94
+ !shallowEquals(nextState, state) ||
95
+ !(
96
+ nextIntl === intl ||
97
+ shallowEquals(
98
+ filterProps(nextIntl, intlConfigPropNames),
99
+ filterProps(intl, intlConfigPropNames)
100
+ )
101
+ )
102
+ );
93
103
  }