react-intl 2.3.0 → 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.
- package/dist/react-intl.js +960 -948
- package/dist/react-intl.js.map +1 -1
- package/dist/react-intl.min.js +1 -2
- package/dist/react-intl.min.js.map +1 -1
- package/lib/index.es.js +971 -970
- package/lib/index.js +971 -970
- package/locale-data/af.js +1 -1
- package/locale-data/agq.js +1 -1
- package/locale-data/ak.js +1 -1
- package/locale-data/am.js +1 -1
- package/locale-data/ar.js +1 -1
- package/locale-data/ars.js +1 -0
- package/locale-data/as.js +1 -1
- package/locale-data/asa.js +1 -1
- package/locale-data/ast.js +1 -1
- package/locale-data/az.js +1 -1
- package/locale-data/bas.js +1 -1
- package/locale-data/be.js +1 -1
- package/locale-data/bem.js +1 -1
- package/locale-data/bez.js +1 -1
- package/locale-data/bg.js +1 -1
- package/locale-data/bh.js +1 -1
- package/locale-data/bm.js +1 -1
- package/locale-data/bn.js +1 -1
- package/locale-data/bo.js +1 -1
- package/locale-data/br.js +1 -1
- package/locale-data/brx.js +1 -1
- package/locale-data/bs.js +1 -1
- package/locale-data/ca.js +1 -1
- package/locale-data/ce.js +1 -1
- package/locale-data/cgg.js +1 -1
- package/locale-data/chr.js +1 -1
- package/locale-data/ckb.js +1 -1
- package/locale-data/cs.js +1 -1
- package/locale-data/cu.js +1 -1
- package/locale-data/cy.js +1 -1
- package/locale-data/da.js +1 -1
- package/locale-data/dav.js +1 -1
- package/locale-data/de.js +1 -1
- package/locale-data/dje.js +1 -1
- package/locale-data/dsb.js +1 -1
- package/locale-data/dua.js +1 -1
- package/locale-data/dv.js +1 -1
- package/locale-data/dyo.js +1 -1
- package/locale-data/dz.js +1 -1
- package/locale-data/ebu.js +1 -1
- package/locale-data/ee.js +1 -1
- package/locale-data/el.js +1 -1
- package/locale-data/en.js +1 -1
- package/locale-data/eo.js +1 -1
- package/locale-data/es.js +1 -1
- package/locale-data/et.js +1 -1
- package/locale-data/eu.js +1 -1
- package/locale-data/ewo.js +1 -1
- package/locale-data/fa.js +1 -1
- package/locale-data/ff.js +1 -1
- package/locale-data/fi.js +1 -1
- package/locale-data/fil.js +1 -1
- package/locale-data/fo.js +1 -1
- package/locale-data/fr.js +1 -1
- package/locale-data/fur.js +1 -1
- package/locale-data/fy.js +1 -1
- package/locale-data/ga.js +1 -1
- package/locale-data/gd.js +1 -1
- package/locale-data/gl.js +1 -1
- package/locale-data/gsw.js +1 -1
- package/locale-data/gu.js +1 -1
- package/locale-data/guw.js +1 -1
- package/locale-data/guz.js +1 -1
- package/locale-data/gv.js +1 -1
- package/locale-data/ha.js +1 -1
- package/locale-data/haw.js +1 -1
- package/locale-data/he.js +1 -1
- package/locale-data/hi.js +1 -1
- package/locale-data/hr.js +1 -1
- package/locale-data/hsb.js +1 -1
- package/locale-data/hu.js +1 -1
- package/locale-data/hy.js +1 -1
- package/locale-data/id.js +1 -1
- package/locale-data/ig.js +1 -1
- package/locale-data/ii.js +1 -1
- package/locale-data/in.js +1 -1
- package/locale-data/index.js +1 -10
- package/locale-data/is.js +1 -1
- package/locale-data/it.js +1 -1
- package/locale-data/iu.js +1 -1
- package/locale-data/iw.js +1 -1
- package/locale-data/ja.js +1 -1
- package/locale-data/jbo.js +1 -1
- package/locale-data/jgo.js +1 -1
- package/locale-data/ji.js +1 -1
- package/locale-data/jmc.js +1 -1
- package/locale-data/jv.js +1 -1
- package/locale-data/jw.js +1 -1
- package/locale-data/ka.js +1 -1
- package/locale-data/kab.js +1 -1
- package/locale-data/kaj.js +1 -1
- package/locale-data/kam.js +1 -1
- package/locale-data/kcg.js +1 -1
- package/locale-data/kde.js +1 -1
- package/locale-data/kea.js +1 -1
- package/locale-data/khq.js +1 -1
- package/locale-data/ki.js +1 -1
- package/locale-data/kk.js +1 -1
- package/locale-data/kkj.js +1 -1
- package/locale-data/kl.js +1 -1
- package/locale-data/kln.js +1 -1
- package/locale-data/km.js +1 -1
- package/locale-data/kn.js +1 -1
- package/locale-data/ko.js +1 -1
- package/locale-data/kok.js +1 -1
- package/locale-data/ks.js +1 -1
- package/locale-data/ksb.js +1 -1
- package/locale-data/ksf.js +1 -1
- package/locale-data/ksh.js +1 -1
- package/locale-data/ku.js +1 -1
- package/locale-data/kw.js +1 -1
- package/locale-data/ky.js +1 -1
- package/locale-data/lag.js +1 -1
- package/locale-data/lb.js +1 -1
- package/locale-data/lg.js +1 -1
- package/locale-data/lkt.js +1 -1
- package/locale-data/ln.js +1 -1
- package/locale-data/lo.js +1 -1
- package/locale-data/lrc.js +1 -1
- package/locale-data/lt.js +1 -1
- package/locale-data/lu.js +1 -1
- package/locale-data/luo.js +1 -1
- package/locale-data/luy.js +1 -1
- package/locale-data/lv.js +1 -1
- package/locale-data/mas.js +1 -1
- package/locale-data/mer.js +1 -1
- package/locale-data/mfe.js +1 -1
- package/locale-data/mg.js +1 -1
- package/locale-data/mgh.js +1 -1
- package/locale-data/mgo.js +1 -1
- package/locale-data/mk.js +1 -1
- package/locale-data/ml.js +1 -1
- package/locale-data/mn.js +1 -1
- package/locale-data/mo.js +1 -1
- package/locale-data/mr.js +1 -1
- package/locale-data/ms.js +1 -1
- package/locale-data/mt.js +1 -1
- package/locale-data/mua.js +1 -1
- package/locale-data/my.js +1 -1
- package/locale-data/mzn.js +1 -1
- package/locale-data/nah.js +1 -1
- package/locale-data/naq.js +1 -1
- package/locale-data/nb.js +1 -1
- package/locale-data/nd.js +1 -1
- package/locale-data/nds.js +1 -0
- package/locale-data/ne.js +1 -1
- package/locale-data/nl.js +1 -1
- package/locale-data/nmg.js +1 -1
- package/locale-data/nn.js +1 -1
- package/locale-data/nnh.js +1 -1
- package/locale-data/no.js +1 -1
- package/locale-data/nqo.js +1 -1
- package/locale-data/nr.js +1 -1
- package/locale-data/nso.js +1 -1
- package/locale-data/nus.js +1 -1
- package/locale-data/ny.js +1 -1
- package/locale-data/nyn.js +1 -1
- package/locale-data/om.js +1 -1
- package/locale-data/or.js +1 -1
- package/locale-data/os.js +1 -1
- package/locale-data/pa.js +1 -1
- package/locale-data/pap.js +1 -1
- package/locale-data/pl.js +1 -1
- package/locale-data/prg.js +1 -1
- package/locale-data/ps.js +1 -1
- package/locale-data/pt.js +1 -1
- package/locale-data/qu.js +1 -1
- package/locale-data/rm.js +1 -1
- package/locale-data/rn.js +1 -1
- package/locale-data/ro.js +1 -1
- package/locale-data/rof.js +1 -1
- package/locale-data/ru.js +1 -1
- package/locale-data/rw.js +1 -1
- package/locale-data/rwk.js +1 -1
- package/locale-data/sah.js +1 -1
- package/locale-data/saq.js +1 -1
- package/locale-data/sbp.js +1 -1
- package/locale-data/sdh.js +1 -1
- package/locale-data/se.js +1 -1
- package/locale-data/seh.js +1 -1
- package/locale-data/ses.js +1 -1
- package/locale-data/sg.js +1 -1
- package/locale-data/sh.js +1 -1
- package/locale-data/shi.js +1 -1
- package/locale-data/si.js +1 -1
- package/locale-data/sk.js +1 -1
- package/locale-data/sl.js +1 -1
- package/locale-data/sma.js +1 -1
- package/locale-data/smi.js +1 -1
- package/locale-data/smj.js +1 -1
- package/locale-data/smn.js +1 -1
- package/locale-data/sms.js +1 -1
- package/locale-data/sn.js +1 -1
- package/locale-data/so.js +1 -1
- package/locale-data/sq.js +1 -1
- package/locale-data/sr.js +1 -1
- package/locale-data/ss.js +1 -1
- package/locale-data/ssy.js +1 -1
- package/locale-data/st.js +1 -1
- package/locale-data/sv.js +1 -1
- package/locale-data/sw.js +1 -1
- package/locale-data/syr.js +1 -1
- package/locale-data/ta.js +1 -1
- package/locale-data/te.js +1 -1
- package/locale-data/teo.js +1 -1
- package/locale-data/th.js +1 -1
- package/locale-data/ti.js +1 -1
- package/locale-data/tig.js +1 -1
- package/locale-data/tk.js +1 -1
- package/locale-data/tl.js +1 -1
- package/locale-data/tn.js +1 -1
- package/locale-data/to.js +1 -1
- package/locale-data/tr.js +1 -1
- package/locale-data/ts.js +1 -1
- package/locale-data/twq.js +1 -1
- package/locale-data/tzm.js +1 -1
- package/locale-data/ug.js +1 -1
- package/locale-data/uk.js +1 -1
- package/locale-data/ur.js +1 -1
- package/locale-data/uz.js +1 -1
- package/locale-data/vai.js +1 -1
- package/locale-data/ve.js +1 -1
- package/locale-data/vi.js +1 -1
- package/locale-data/vo.js +1 -1
- package/locale-data/vun.js +1 -1
- package/locale-data/wa.js +1 -1
- package/locale-data/wae.js +1 -1
- package/locale-data/wo.js +1 -1
- package/locale-data/xh.js +1 -1
- package/locale-data/xog.js +1 -1
- package/locale-data/yav.js +1 -1
- package/locale-data/yi.js +1 -1
- package/locale-data/yo.js +1 -1
- package/locale-data/yue.js +1 -0
- package/locale-data/zgh.js +1 -1
- package/locale-data/zh.js +1 -1
- package/locale-data/zu.js +1 -1
- package/package.json +11 -9
- package/src/components/date.js +47 -0
- package/src/components/html-message.js +88 -0
- package/src/components/message.js +137 -0
- package/src/components/number.js +47 -0
- package/src/components/plural.js +59 -0
- package/src/components/provider.js +177 -0
- package/src/components/relative.js +171 -0
- package/src/components/time.js +47 -0
- package/src/define-messages.js +11 -0
- package/src/en.js +2 -0
- package/src/format.js +276 -0
- package/src/index.js +12 -0
- package/src/inject.js +59 -0
- package/src/locale-data-registry.js +42 -0
- package/src/plural.js +28 -0
- package/src/react-intl.js +24 -0
- package/src/types.js +98 -0
- package/src/utils.js +103 -0
- package/yarn.lock +87 -59
package/lib/index.es.js
CHANGED
|
@@ -19,7 +19,7 @@ var defaultLocaleData = { "locale": "en", "pluralRuleFunction": function pluralR
|
|
|
19
19
|
t0 = Number(s[0]) == n,
|
|
20
20
|
n10 = t0 && s[0].slice(-1),
|
|
21
21
|
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";
|
|
22
|
-
}, "fields": { "year": { "displayName": "year", "relative": { "0": "this year", "1": "next year", "-1": "last year" }, "relativeTime": { "future": { "one": "in {0} year", "other": "in {0} years" }, "past": { "one": "{0} year ago", "other": "{0} years ago" } } }, "month": { "displayName": "month", "relative": { "0": "this month", "1": "next month", "-1": "last month" }, "relativeTime": { "future": { "one": "in {0} month", "other": "in {0} months" }, "past": { "one": "{0} month ago", "other": "{0} months ago" } } }, "day": { "displayName": "day", "relative": { "0": "today", "1": "tomorrow", "-1": "yesterday" }, "relativeTime": { "future": { "one": "in {0} day", "other": "in {0} days" }, "past": { "one": "{0} day ago", "other": "{0} days ago" } } }, "hour": { "displayName": "hour", "relativeTime": { "future": { "one": "in {0} hour", "other": "in {0} hours" }, "past": { "one": "{0} hour ago", "other": "{0} hours ago" } } }, "minute": { "displayName": "minute", "relativeTime": { "future": { "one": "in {0} minute", "other": "in {0} minutes" }, "past": { "one": "{0} minute ago", "other": "{0} minutes ago" } } }, "second": { "displayName": "second", "relative": { "0": "now" }, "relativeTime": { "future": { "one": "in {0} second", "other": "in {0} seconds" }, "past": { "one": "{0} second ago", "other": "{0} seconds ago" } } } } };
|
|
22
|
+
}, "fields": { "year": { "displayName": "year", "relative": { "0": "this year", "1": "next year", "-1": "last year" }, "relativeTime": { "future": { "one": "in {0} year", "other": "in {0} years" }, "past": { "one": "{0} year ago", "other": "{0} years ago" } } }, "month": { "displayName": "month", "relative": { "0": "this month", "1": "next month", "-1": "last month" }, "relativeTime": { "future": { "one": "in {0} month", "other": "in {0} months" }, "past": { "one": "{0} month ago", "other": "{0} months ago" } } }, "day": { "displayName": "day", "relative": { "0": "today", "1": "tomorrow", "-1": "yesterday" }, "relativeTime": { "future": { "one": "in {0} day", "other": "in {0} days" }, "past": { "one": "{0} day ago", "other": "{0} days ago" } } }, "hour": { "displayName": "hour", "relative": { "0": "this hour" }, "relativeTime": { "future": { "one": "in {0} hour", "other": "in {0} hours" }, "past": { "one": "{0} hour ago", "other": "{0} hours ago" } } }, "minute": { "displayName": "minute", "relative": { "0": "this minute" }, "relativeTime": { "future": { "one": "in {0} minute", "other": "in {0} minutes" }, "past": { "one": "{0} minute ago", "other": "{0} minutes ago" } } }, "second": { "displayName": "second", "relative": { "0": "now" }, "relativeTime": { "future": { "one": "in {0} second", "other": "in {0} seconds" }, "past": { "one": "{0} second ago", "other": "{0} seconds ago" } } } } };
|
|
23
23
|
|
|
24
24
|
/*
|
|
25
25
|
* Copyright 2015, Yahoo Inc.
|
|
@@ -28,36 +28,36 @@ var defaultLocaleData = { "locale": "en", "pluralRuleFunction": function pluralR
|
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
30
|
function addLocaleData() {
|
|
31
|
-
|
|
31
|
+
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
var locales = Array.isArray(data) ? data : [data];
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
locales.forEach(function (localeData) {
|
|
36
|
+
if (localeData && localeData.locale) {
|
|
37
|
+
IntlMessageFormat.__addLocaleData(localeData);
|
|
38
|
+
IntlRelativeFormat.__addLocaleData(localeData);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
function hasLocaleData(locale) {
|
|
44
|
-
|
|
44
|
+
var localeParts = (locale || '').split('-');
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
localeParts.pop();
|
|
46
|
+
while (localeParts.length > 0) {
|
|
47
|
+
if (hasIMFAndIRFLocaleData(localeParts.join('-'))) {
|
|
48
|
+
return true;
|
|
52
49
|
}
|
|
53
50
|
|
|
54
|
-
|
|
51
|
+
localeParts.pop();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return false;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
function hasIMFAndIRFLocaleData(locale) {
|
|
58
|
-
|
|
58
|
+
var normalizedLocale = locale && locale.toLowerCase();
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
return !!(IntlMessageFormat.__localeData__[normalizedLocale] && IntlRelativeFormat.__localeData__[normalizedLocale]);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
|
|
@@ -221,6 +221,7 @@ var object = PropTypes.object;
|
|
|
221
221
|
var oneOf = PropTypes.oneOf;
|
|
222
222
|
var shape = PropTypes.shape;
|
|
223
223
|
var any = PropTypes.any;
|
|
224
|
+
var oneOfType = PropTypes.oneOfType;
|
|
224
225
|
|
|
225
226
|
var localeMatcher = oneOf(['best fit', 'lookup']);
|
|
226
227
|
var narrowShortLong = oneOf(['narrow', 'short', 'long']);
|
|
@@ -228,76 +229,76 @@ var numeric2digit = oneOf(['numeric', '2-digit']);
|
|
|
228
229
|
var funcReq = func.isRequired;
|
|
229
230
|
|
|
230
231
|
var intlConfigPropTypes = {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
232
|
+
locale: string,
|
|
233
|
+
formats: object,
|
|
234
|
+
messages: object,
|
|
235
|
+
textComponent: any,
|
|
235
236
|
|
|
236
|
-
|
|
237
|
-
|
|
237
|
+
defaultLocale: string,
|
|
238
|
+
defaultFormats: object
|
|
238
239
|
};
|
|
239
240
|
|
|
240
241
|
var intlFormatPropTypes = {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
242
|
+
formatDate: funcReq,
|
|
243
|
+
formatTime: funcReq,
|
|
244
|
+
formatRelative: funcReq,
|
|
245
|
+
formatNumber: funcReq,
|
|
246
|
+
formatPlural: funcReq,
|
|
247
|
+
formatMessage: funcReq,
|
|
248
|
+
formatHTMLMessage: funcReq
|
|
248
249
|
};
|
|
249
250
|
|
|
250
251
|
var intlShape = shape(_extends({}, intlConfigPropTypes, intlFormatPropTypes, {
|
|
251
|
-
|
|
252
|
-
|
|
252
|
+
formatters: object,
|
|
253
|
+
now: funcReq
|
|
253
254
|
}));
|
|
254
255
|
|
|
255
256
|
var messageDescriptorPropTypes = {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
257
|
+
id: string.isRequired,
|
|
258
|
+
description: oneOfType([string, object]),
|
|
259
|
+
defaultMessage: string
|
|
259
260
|
};
|
|
260
261
|
|
|
261
262
|
var dateTimeFormatPropTypes = {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
263
|
+
localeMatcher: localeMatcher,
|
|
264
|
+
formatMatcher: oneOf(['basic', 'best fit']),
|
|
265
|
+
|
|
266
|
+
timeZone: string,
|
|
267
|
+
hour12: bool,
|
|
268
|
+
|
|
269
|
+
weekday: narrowShortLong,
|
|
270
|
+
era: narrowShortLong,
|
|
271
|
+
year: numeric2digit,
|
|
272
|
+
month: oneOf(['numeric', '2-digit', 'narrow', 'short', 'long']),
|
|
273
|
+
day: numeric2digit,
|
|
274
|
+
hour: numeric2digit,
|
|
275
|
+
minute: numeric2digit,
|
|
276
|
+
second: numeric2digit,
|
|
277
|
+
timeZoneName: oneOf(['short', 'long'])
|
|
277
278
|
};
|
|
278
279
|
|
|
279
280
|
var numberFormatPropTypes = {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
281
|
+
localeMatcher: localeMatcher,
|
|
282
|
+
|
|
283
|
+
style: oneOf(['decimal', 'currency', 'percent']),
|
|
284
|
+
currency: string,
|
|
285
|
+
currencyDisplay: oneOf(['symbol', 'code', 'name']),
|
|
286
|
+
useGrouping: bool,
|
|
287
|
+
|
|
288
|
+
minimumIntegerDigits: number,
|
|
289
|
+
minimumFractionDigits: number,
|
|
290
|
+
maximumFractionDigits: number,
|
|
291
|
+
minimumSignificantDigits: number,
|
|
292
|
+
maximumSignificantDigits: number
|
|
292
293
|
};
|
|
293
294
|
|
|
294
295
|
var relativeFormatPropTypes = {
|
|
295
|
-
|
|
296
|
-
|
|
296
|
+
style: oneOf(['best fit', 'numeric']),
|
|
297
|
+
units: oneOf(['second', 'minute', 'hour', 'day', 'month', 'year'])
|
|
297
298
|
};
|
|
298
299
|
|
|
299
300
|
var pluralFormatPropTypes = {
|
|
300
|
-
|
|
301
|
+
style: oneOf(['cardinal', 'ordinal'])
|
|
301
302
|
};
|
|
302
303
|
|
|
303
304
|
/*
|
|
@@ -314,82 +315,82 @@ file in the root directory of React's source tree.
|
|
|
314
315
|
var intlConfigPropNames = Object.keys(intlConfigPropTypes);
|
|
315
316
|
|
|
316
317
|
var ESCAPED_CHARS = {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
318
|
+
'&': '&',
|
|
319
|
+
'>': '>',
|
|
320
|
+
'<': '<',
|
|
321
|
+
'"': '"',
|
|
322
|
+
"'": '''
|
|
322
323
|
};
|
|
323
324
|
|
|
324
325
|
var UNSAFE_CHARS_REGEX = /[&><"']/g;
|
|
325
326
|
|
|
326
327
|
function escape(str) {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
328
|
+
return ('' + str).replace(UNSAFE_CHARS_REGEX, function (match) {
|
|
329
|
+
return ESCAPED_CHARS[match];
|
|
330
|
+
});
|
|
330
331
|
}
|
|
331
332
|
|
|
332
333
|
function filterProps(props, whitelist) {
|
|
333
|
-
|
|
334
|
+
var defaults$$1 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
334
335
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
336
|
+
return whitelist.reduce(function (filtered, name) {
|
|
337
|
+
if (props.hasOwnProperty(name)) {
|
|
338
|
+
filtered[name] = props[name];
|
|
339
|
+
} else if (defaults$$1.hasOwnProperty(name)) {
|
|
340
|
+
filtered[name] = defaults$$1[name];
|
|
341
|
+
}
|
|
341
342
|
|
|
342
|
-
|
|
343
|
-
|
|
343
|
+
return filtered;
|
|
344
|
+
}, {});
|
|
344
345
|
}
|
|
345
346
|
|
|
346
347
|
function invariantIntlContext() {
|
|
347
|
-
|
|
348
|
-
|
|
348
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
349
|
+
intl = _ref.intl;
|
|
349
350
|
|
|
350
|
-
|
|
351
|
+
invariant(intl, '[React Intl] Could not find required `intl` object. ' + '<IntlProvider> needs to exist in the component ancestry.');
|
|
351
352
|
}
|
|
352
353
|
|
|
353
354
|
function shallowEquals(objA, objB) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
355
|
+
if (objA === objB) {
|
|
356
|
+
return true;
|
|
357
|
+
}
|
|
357
358
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
359
|
+
if ((typeof objA === 'undefined' ? 'undefined' : _typeof(objA)) !== 'object' || objA === null || (typeof objB === 'undefined' ? 'undefined' : _typeof(objB)) !== 'object' || objB === null) {
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
361
362
|
|
|
362
|
-
|
|
363
|
-
|
|
363
|
+
var keysA = Object.keys(objA);
|
|
364
|
+
var keysB = Object.keys(objB);
|
|
364
365
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
366
|
+
if (keysA.length !== keysB.length) {
|
|
367
|
+
return false;
|
|
368
|
+
}
|
|
368
369
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
}
|
|
370
|
+
// Test for A's keys different from B.
|
|
371
|
+
var bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB);
|
|
372
|
+
for (var i = 0; i < keysA.length; i++) {
|
|
373
|
+
if (!bHasOwnProperty(keysA[i]) || objA[keysA[i]] !== objB[keysA[i]]) {
|
|
374
|
+
return false;
|
|
375
375
|
}
|
|
376
|
+
}
|
|
376
377
|
|
|
377
|
-
|
|
378
|
+
return true;
|
|
378
379
|
}
|
|
379
380
|
|
|
380
381
|
function shouldIntlComponentUpdate(_ref2, nextProps, nextState) {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
382
|
+
var props = _ref2.props,
|
|
383
|
+
state = _ref2.state,
|
|
384
|
+
_ref2$context = _ref2.context,
|
|
385
|
+
context = _ref2$context === undefined ? {} : _ref2$context;
|
|
386
|
+
var nextContext = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
387
|
+
var _context$intl = context.intl,
|
|
388
|
+
intl = _context$intl === undefined ? {} : _context$intl;
|
|
389
|
+
var _nextContext$intl = nextContext.intl,
|
|
390
|
+
nextIntl = _nextContext$intl === undefined ? {} : _nextContext$intl;
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
return !shallowEquals(nextProps, props) || !shallowEquals(nextState, state) || !(nextIntl === intl || shallowEquals(filterProps(nextIntl, intlConfigPropNames), filterProps(intl, intlConfigPropNames)));
|
|
393
394
|
}
|
|
394
395
|
|
|
395
396
|
/*
|
|
@@ -402,54 +403,54 @@ function shouldIntlComponentUpdate(_ref2, nextProps, nextState) {
|
|
|
402
403
|
// https://github.com/rackt/react-redux
|
|
403
404
|
|
|
404
405
|
function getDisplayName(Component$$1) {
|
|
405
|
-
|
|
406
|
+
return Component$$1.displayName || Component$$1.name || 'Component';
|
|
406
407
|
}
|
|
407
408
|
|
|
408
409
|
function injectIntl(WrappedComponent) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
410
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
411
|
+
var _options$intlPropName = options.intlPropName,
|
|
412
|
+
intlPropName = _options$intlPropName === undefined ? 'intl' : _options$intlPropName,
|
|
413
|
+
_options$withRef = options.withRef,
|
|
414
|
+
withRef = _options$withRef === undefined ? false : _options$withRef;
|
|
414
415
|
|
|
415
|
-
|
|
416
|
-
|
|
416
|
+
var InjectIntl = function (_Component) {
|
|
417
|
+
inherits(InjectIntl, _Component);
|
|
417
418
|
|
|
418
|
-
|
|
419
|
-
|
|
419
|
+
function InjectIntl(props, context) {
|
|
420
|
+
classCallCheck(this, InjectIntl);
|
|
420
421
|
|
|
421
|
-
|
|
422
|
+
var _this = possibleConstructorReturn(this, (InjectIntl.__proto__ || Object.getPrototypeOf(InjectIntl)).call(this, props, context));
|
|
422
423
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
createClass(InjectIntl, [{
|
|
428
|
-
key: 'getWrappedInstance',
|
|
429
|
-
value: function getWrappedInstance() {
|
|
430
|
-
invariant(withRef, '[React Intl] To access the wrapped instance, ' + 'the `{withRef: true}` option must be set when calling: ' + '`injectIntl()`');
|
|
431
|
-
|
|
432
|
-
return this.refs.wrappedInstance;
|
|
433
|
-
}
|
|
434
|
-
}, {
|
|
435
|
-
key: 'render',
|
|
436
|
-
value: function render() {
|
|
437
|
-
return React.createElement(WrappedComponent, _extends({}, this.props, defineProperty({}, intlPropName, this.context.intl), {
|
|
438
|
-
ref: withRef ? 'wrappedInstance' : null
|
|
439
|
-
}));
|
|
440
|
-
}
|
|
441
|
-
}]);
|
|
442
|
-
return InjectIntl;
|
|
443
|
-
}(Component);
|
|
444
|
-
|
|
445
|
-
InjectIntl.displayName = 'InjectIntl(' + getDisplayName(WrappedComponent) + ')';
|
|
446
|
-
InjectIntl.contextTypes = {
|
|
447
|
-
intl: intlShape
|
|
448
|
-
};
|
|
449
|
-
InjectIntl.WrappedComponent = WrappedComponent;
|
|
424
|
+
invariantIntlContext(context);
|
|
425
|
+
return _this;
|
|
426
|
+
}
|
|
450
427
|
|
|
428
|
+
createClass(InjectIntl, [{
|
|
429
|
+
key: 'getWrappedInstance',
|
|
430
|
+
value: function getWrappedInstance() {
|
|
431
|
+
invariant(withRef, '[React Intl] To access the wrapped instance, ' + 'the `{withRef: true}` option must be set when calling: ' + '`injectIntl()`');
|
|
451
432
|
|
|
433
|
+
return this.refs.wrappedInstance;
|
|
434
|
+
}
|
|
435
|
+
}, {
|
|
436
|
+
key: 'render',
|
|
437
|
+
value: function render() {
|
|
438
|
+
return React.createElement(WrappedComponent, _extends({}, this.props, defineProperty({}, intlPropName, this.context.intl), {
|
|
439
|
+
ref: withRef ? 'wrappedInstance' : null
|
|
440
|
+
}));
|
|
441
|
+
}
|
|
442
|
+
}]);
|
|
452
443
|
return InjectIntl;
|
|
444
|
+
}(Component);
|
|
445
|
+
|
|
446
|
+
InjectIntl.displayName = 'InjectIntl(' + getDisplayName(WrappedComponent) + ')';
|
|
447
|
+
InjectIntl.contextTypes = {
|
|
448
|
+
intl: intlShape
|
|
449
|
+
};
|
|
450
|
+
InjectIntl.WrappedComponent = WrappedComponent;
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
return InjectIntl;
|
|
453
454
|
}
|
|
454
455
|
|
|
455
456
|
/*
|
|
@@ -473,25 +474,25 @@ function defineMessages(messageDescriptors) {
|
|
|
473
474
|
// This is a "hack" until a proper `intl-pluralformat` package is created.
|
|
474
475
|
|
|
475
476
|
function resolveLocale(locales) {
|
|
476
|
-
|
|
477
|
-
|
|
477
|
+
// IntlMessageFormat#_resolveLocale() does not depend on `this`.
|
|
478
|
+
return IntlMessageFormat.prototype._resolveLocale(locales);
|
|
478
479
|
}
|
|
479
480
|
|
|
480
481
|
function findPluralFunction(locale) {
|
|
481
|
-
|
|
482
|
-
|
|
482
|
+
// IntlMessageFormat#_findPluralFunction() does not depend on `this`.
|
|
483
|
+
return IntlMessageFormat.prototype._findPluralRuleFunction(locale);
|
|
483
484
|
}
|
|
484
485
|
|
|
485
486
|
var IntlPluralFormat = function IntlPluralFormat(locales) {
|
|
486
|
-
|
|
487
|
-
|
|
487
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
488
|
+
classCallCheck(this, IntlPluralFormat);
|
|
488
489
|
|
|
489
|
-
|
|
490
|
-
|
|
490
|
+
var useOrdinal = options.style === 'ordinal';
|
|
491
|
+
var pluralFn = findPluralFunction(resolveLocale(locales));
|
|
491
492
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
493
|
+
this.format = function (value) {
|
|
494
|
+
return pluralFn(value, useOrdinal);
|
|
495
|
+
};
|
|
495
496
|
};
|
|
496
497
|
|
|
497
498
|
/*
|
|
@@ -506,234 +507,234 @@ var RELATIVE_FORMAT_OPTIONS = Object.keys(relativeFormatPropTypes);
|
|
|
506
507
|
var PLURAL_FORMAT_OPTIONS = Object.keys(pluralFormatPropTypes);
|
|
507
508
|
|
|
508
509
|
var RELATIVE_FORMAT_THRESHOLDS = {
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
510
|
+
second: 60, // seconds to minute
|
|
511
|
+
minute: 60, // minutes to hour
|
|
512
|
+
hour: 24, // hours to day
|
|
513
|
+
day: 30, // days to month
|
|
514
|
+
month: 12 // months to year
|
|
515
|
+
};
|
|
514
516
|
|
|
515
517
|
function updateRelativeFormatThresholds(newThresholds) {
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
518
|
+
var thresholds = IntlRelativeFormat.thresholds;
|
|
519
|
+
thresholds.second = newThresholds.second;
|
|
520
|
+
thresholds.minute = newThresholds.minute;
|
|
521
|
+
thresholds.hour = newThresholds.hour;
|
|
522
|
+
thresholds.day = newThresholds.day;
|
|
523
|
+
thresholds.month = newThresholds.month;
|
|
522
524
|
}
|
|
523
525
|
|
|
524
526
|
function getNamedFormat(formats, type, name) {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
527
|
+
var format = formats && formats[type] && formats[type][name];
|
|
528
|
+
if (format) {
|
|
529
|
+
return format;
|
|
530
|
+
}
|
|
529
531
|
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
532
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
533
|
+
console.error('[React Intl] No ' + type + ' format named: ' + name);
|
|
534
|
+
}
|
|
533
535
|
}
|
|
534
536
|
|
|
535
537
|
function formatDate(config, state, value) {
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
538
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
539
|
+
var locale = config.locale,
|
|
540
|
+
formats = config.formats;
|
|
541
|
+
var format = options.format;
|
|
540
542
|
|
|
541
543
|
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
544
|
+
var date = new Date(value);
|
|
545
|
+
var defaults$$1 = format && getNamedFormat(formats, 'date', format);
|
|
546
|
+
var filteredOptions = filterProps(options, DATE_TIME_FORMAT_OPTIONS, defaults$$1);
|
|
545
547
|
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
}
|
|
548
|
+
try {
|
|
549
|
+
return state.getDateTimeFormat(locale, filteredOptions).format(date);
|
|
550
|
+
} catch (e) {
|
|
551
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
552
|
+
console.error('[React Intl] Error formatting date.\n' + e);
|
|
552
553
|
}
|
|
554
|
+
}
|
|
553
555
|
|
|
554
|
-
|
|
556
|
+
return String(date);
|
|
555
557
|
}
|
|
556
558
|
|
|
557
559
|
function formatTime(config, state, value) {
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
560
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
561
|
+
var locale = config.locale,
|
|
562
|
+
formats = config.formats;
|
|
563
|
+
var format = options.format;
|
|
562
564
|
|
|
563
565
|
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
566
|
+
var date = new Date(value);
|
|
567
|
+
var defaults$$1 = format && getNamedFormat(formats, 'time', format);
|
|
568
|
+
var filteredOptions = filterProps(options, DATE_TIME_FORMAT_OPTIONS, defaults$$1);
|
|
567
569
|
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
570
|
+
if (!filteredOptions.hour && !filteredOptions.minute && !filteredOptions.second) {
|
|
571
|
+
// Add default formatting options if hour, minute, or second isn't defined.
|
|
572
|
+
filteredOptions = _extends({}, filteredOptions, { hour: 'numeric', minute: 'numeric' });
|
|
573
|
+
}
|
|
572
574
|
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
}
|
|
575
|
+
try {
|
|
576
|
+
return state.getDateTimeFormat(locale, filteredOptions).format(date);
|
|
577
|
+
} catch (e) {
|
|
578
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
579
|
+
console.error('[React Intl] Error formatting time.\n' + e);
|
|
579
580
|
}
|
|
581
|
+
}
|
|
580
582
|
|
|
581
|
-
|
|
583
|
+
return String(date);
|
|
582
584
|
}
|
|
583
585
|
|
|
584
586
|
function formatRelative(config, state, value) {
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
587
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
588
|
+
var locale = config.locale,
|
|
589
|
+
formats = config.formats;
|
|
590
|
+
var format = options.format;
|
|
589
591
|
|
|
590
592
|
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
593
|
+
var date = new Date(value);
|
|
594
|
+
var now = new Date(options.now);
|
|
595
|
+
var defaults$$1 = format && getNamedFormat(formats, 'relative', format);
|
|
596
|
+
var filteredOptions = filterProps(options, RELATIVE_FORMAT_OPTIONS, defaults$$1);
|
|
595
597
|
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
598
|
+
// Capture the current threshold values, then temporarily override them with
|
|
599
|
+
// specific values just for this render.
|
|
600
|
+
var oldThresholds = _extends({}, IntlRelativeFormat.thresholds);
|
|
601
|
+
updateRelativeFormatThresholds(RELATIVE_FORMAT_THRESHOLDS);
|
|
600
602
|
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
}
|
|
609
|
-
} finally {
|
|
610
|
-
updateRelativeFormatThresholds(oldThresholds);
|
|
603
|
+
try {
|
|
604
|
+
return state.getRelativeFormat(locale, filteredOptions).format(date, {
|
|
605
|
+
now: isFinite(now) ? now : state.now()
|
|
606
|
+
});
|
|
607
|
+
} catch (e) {
|
|
608
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
609
|
+
console.error('[React Intl] Error formatting relative time.\n' + e);
|
|
611
610
|
}
|
|
611
|
+
} finally {
|
|
612
|
+
updateRelativeFormatThresholds(oldThresholds);
|
|
613
|
+
}
|
|
612
614
|
|
|
613
|
-
|
|
615
|
+
return String(date);
|
|
614
616
|
}
|
|
615
617
|
|
|
616
618
|
function formatNumber(config, state, value) {
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
619
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
620
|
+
var locale = config.locale,
|
|
621
|
+
formats = config.formats;
|
|
622
|
+
var format = options.format;
|
|
621
623
|
|
|
622
624
|
|
|
623
|
-
|
|
624
|
-
|
|
625
|
+
var defaults$$1 = format && getNamedFormat(formats, 'number', format);
|
|
626
|
+
var filteredOptions = filterProps(options, NUMBER_FORMAT_OPTIONS, defaults$$1);
|
|
625
627
|
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
}
|
|
628
|
+
try {
|
|
629
|
+
return state.getNumberFormat(locale, filteredOptions).format(value);
|
|
630
|
+
} catch (e) {
|
|
631
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
632
|
+
console.error('[React Intl] Error formatting number.\n' + e);
|
|
632
633
|
}
|
|
634
|
+
}
|
|
633
635
|
|
|
634
|
-
|
|
636
|
+
return String(value);
|
|
635
637
|
}
|
|
636
638
|
|
|
637
639
|
function formatPlural(config, state, value) {
|
|
638
|
-
|
|
639
|
-
|
|
640
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
641
|
+
var locale = config.locale;
|
|
640
642
|
|
|
641
643
|
|
|
642
|
-
|
|
644
|
+
var filteredOptions = filterProps(options, PLURAL_FORMAT_OPTIONS);
|
|
643
645
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
}
|
|
646
|
+
try {
|
|
647
|
+
return state.getPluralFormat(locale, filteredOptions).format(value);
|
|
648
|
+
} catch (e) {
|
|
649
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
650
|
+
console.error('[React Intl] Error formatting plural.\n' + e);
|
|
650
651
|
}
|
|
652
|
+
}
|
|
651
653
|
|
|
652
|
-
|
|
654
|
+
return 'other';
|
|
653
655
|
}
|
|
654
656
|
|
|
655
657
|
function formatMessage(config, state) {
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
var formattedMessage = void 0;
|
|
658
|
+
var messageDescriptor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
659
|
+
var values = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
660
|
+
var locale = config.locale,
|
|
661
|
+
formats = config.formats,
|
|
662
|
+
messages = config.messages,
|
|
663
|
+
defaultLocale = config.defaultLocale,
|
|
664
|
+
defaultFormats = config.defaultFormats;
|
|
665
|
+
var id = messageDescriptor.id,
|
|
666
|
+
defaultMessage = messageDescriptor.defaultMessage;
|
|
667
|
+
|
|
668
|
+
// `id` is a required field of a Message Descriptor.
|
|
669
|
+
|
|
670
|
+
invariant(id, '[React Intl] An `id` must be provided to format a message.');
|
|
671
|
+
|
|
672
|
+
var message = messages && messages[id];
|
|
673
|
+
var hasValues = Object.keys(values).length > 0;
|
|
674
|
+
|
|
675
|
+
// Avoid expensive message formatting for simple messages without values. In
|
|
676
|
+
// development messages will always be formatted in case of missing values.
|
|
677
|
+
if (!hasValues && process.env.NODE_ENV === 'production') {
|
|
678
|
+
return message || defaultMessage || id;
|
|
679
|
+
}
|
|
680
680
|
|
|
681
|
-
|
|
682
|
-
try {
|
|
683
|
-
var formatter = state.getMessageFormat(message, locale, formats);
|
|
681
|
+
var formattedMessage = void 0;
|
|
684
682
|
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
console.error('[React Intl] Error formatting message: "' + id + '" for locale: "' + locale + '"' + (defaultMessage ? ', using default message as fallback.' : '') + ('\n' + e));
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
} else {
|
|
692
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
693
|
-
// This prevents warnings from littering the console in development
|
|
694
|
-
// when no `messages` are passed into the <IntlProvider> for the
|
|
695
|
-
// default locale, and a default message is in the source.
|
|
696
|
-
if (!defaultMessage || locale && locale.toLowerCase() !== defaultLocale.toLowerCase()) {
|
|
683
|
+
if (message) {
|
|
684
|
+
try {
|
|
685
|
+
var formatter = state.getMessageFormat(message, locale, formats);
|
|
697
686
|
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
687
|
+
formattedMessage = formatter.format(values);
|
|
688
|
+
} catch (e) {
|
|
689
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
690
|
+
console.error('[React Intl] Error formatting message: "' + id + '" for locale: "' + locale + '"' + (defaultMessage ? ', using default message as fallback.' : '') + ('\n' + e));
|
|
691
|
+
}
|
|
701
692
|
}
|
|
693
|
+
} else {
|
|
694
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
695
|
+
// This prevents warnings from littering the console in development
|
|
696
|
+
// when no `messages` are passed into the <IntlProvider> for the
|
|
697
|
+
// default locale, and a default message is in the source.
|
|
698
|
+
if (!defaultMessage || locale && locale.toLowerCase() !== defaultLocale.toLowerCase()) {
|
|
699
|
+
console.error('[React Intl] Missing message: "' + id + '" for locale: "' + locale + '"' + (defaultMessage ? ', using default message as fallback.' : ''));
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
}
|
|
702
703
|
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
704
|
+
if (!formattedMessage && defaultMessage) {
|
|
705
|
+
try {
|
|
706
|
+
var _formatter = state.getMessageFormat(defaultMessage, defaultLocale, defaultFormats);
|
|
706
707
|
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
}
|
|
708
|
+
formattedMessage = _formatter.format(values);
|
|
709
|
+
} catch (e) {
|
|
710
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
711
|
+
console.error('[React Intl] Error formatting the default message for: "' + id + '"' + ('\n' + e));
|
|
712
|
+
}
|
|
713
713
|
}
|
|
714
|
+
}
|
|
714
715
|
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
}
|
|
716
|
+
if (!formattedMessage) {
|
|
717
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
718
|
+
console.error('[React Intl] Cannot format message: "' + id + '", ' + ('using message ' + (message || defaultMessage ? 'source' : 'id') + ' as fallback.'));
|
|
719
719
|
}
|
|
720
|
+
}
|
|
720
721
|
|
|
721
|
-
|
|
722
|
+
return formattedMessage || message || defaultMessage || id;
|
|
722
723
|
}
|
|
723
724
|
|
|
724
725
|
function formatHTMLMessage(config, state, messageDescriptor) {
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
726
|
+
var rawValues = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
727
|
+
|
|
728
|
+
// Process all the values before they are used when formatting the ICU
|
|
729
|
+
// Message string. Since the formatted message might be injected via
|
|
730
|
+
// `innerHTML`, all String-based values need to be HTML-escaped.
|
|
731
|
+
var escapedValues = Object.keys(rawValues).reduce(function (escaped, name) {
|
|
732
|
+
var value = rawValues[name];
|
|
733
|
+
escaped[name] = typeof value === 'string' ? escape(value) : value;
|
|
734
|
+
return escaped;
|
|
735
|
+
}, {});
|
|
736
|
+
|
|
737
|
+
return formatMessage(config, state, messageDescriptor, escapedValues);
|
|
737
738
|
}
|
|
738
739
|
|
|
739
740
|
|
|
@@ -760,170 +761,170 @@ var intlFormatPropNames = Object.keys(intlFormatPropTypes);
|
|
|
760
761
|
// These are not a static property on the `IntlProvider` class so the intl
|
|
761
762
|
// config values can be inherited from an <IntlProvider> ancestor.
|
|
762
763
|
var defaultProps = {
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
764
|
+
formats: {},
|
|
765
|
+
messages: {},
|
|
766
|
+
textComponent: 'span',
|
|
766
767
|
|
|
767
|
-
|
|
768
|
-
|
|
768
|
+
defaultLocale: 'en',
|
|
769
|
+
defaultFormats: {}
|
|
769
770
|
};
|
|
770
771
|
|
|
771
772
|
var IntlProvider = function (_Component) {
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
function IntlProvider(props) {
|
|
775
|
-
var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
776
|
-
classCallCheck(this, IntlProvider);
|
|
773
|
+
inherits(IntlProvider, _Component);
|
|
777
774
|
|
|
778
|
-
|
|
775
|
+
function IntlProvider(props) {
|
|
776
|
+
var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
777
|
+
classCallCheck(this, IntlProvider);
|
|
779
778
|
|
|
780
|
-
|
|
779
|
+
var _this = possibleConstructorReturn(this, (IntlProvider.__proto__ || Object.getPrototypeOf(IntlProvider)).call(this, props, context));
|
|
781
780
|
|
|
782
|
-
|
|
781
|
+
invariant(typeof Intl !== 'undefined', '[React Intl] The `Intl` APIs must be available in the runtime, ' + 'and do not appear to be built-in. An `Intl` polyfill should be loaded.\n' + 'See: http://formatjs.io/guides/runtime-environments/');
|
|
783
782
|
|
|
784
|
-
|
|
785
|
-
// all relative times use the same reference "now" time.
|
|
783
|
+
var intlContext = context.intl;
|
|
786
784
|
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
initialNow = Number(props.initialNow);
|
|
790
|
-
} else {
|
|
791
|
-
// When an `initialNow` isn't provided via `props`, look to see an
|
|
792
|
-
// <IntlProvider> exists in the ancestry and call its `now()`
|
|
793
|
-
// function to propagate its value for "now".
|
|
794
|
-
initialNow = intlContext ? intlContext.now() : Date.now();
|
|
795
|
-
}
|
|
785
|
+
// Used to stabilize time when performing an initial rendering so that
|
|
786
|
+
// all relative times use the same reference "now" time.
|
|
796
787
|
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
getDateTimeFormat: memoizeIntlConstructor(Intl.DateTimeFormat),
|
|
806
|
-
getNumberFormat: memoizeIntlConstructor(Intl.NumberFormat),
|
|
807
|
-
getMessageFormat: memoizeIntlConstructor(IntlMessageFormat),
|
|
808
|
-
getRelativeFormat: memoizeIntlConstructor(IntlRelativeFormat),
|
|
809
|
-
getPluralFormat: memoizeIntlConstructor(IntlPluralFormat)
|
|
810
|
-
} : _ref$formatters;
|
|
811
|
-
|
|
812
|
-
_this.state = _extends({}, formatters, {
|
|
813
|
-
|
|
814
|
-
// Wrapper to provide stable "now" time for initial render.
|
|
815
|
-
now: function now() {
|
|
816
|
-
return _this._didDisplay ? Date.now() : initialNow;
|
|
817
|
-
}
|
|
818
|
-
});
|
|
819
|
-
return _this;
|
|
788
|
+
var initialNow = void 0;
|
|
789
|
+
if (isFinite(props.initialNow)) {
|
|
790
|
+
initialNow = Number(props.initialNow);
|
|
791
|
+
} else {
|
|
792
|
+
// When an `initialNow` isn't provided via `props`, look to see an
|
|
793
|
+
// <IntlProvider> exists in the ancestry and call its `now()`
|
|
794
|
+
// function to propagate its value for "now".
|
|
795
|
+
initialNow = intlContext ? intlContext.now() : Date.now();
|
|
820
796
|
}
|
|
821
797
|
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
849
|
-
console.error('[React Intl] Missing locale data for locale: "' + locale + '". ' + ('Using default locale: "' + defaultLocale + '" as fallback.'));
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
// Since there's no registered locale data for `locale`, this will
|
|
853
|
-
// fallback to the `defaultLocale` to make sure things can render.
|
|
854
|
-
// The `messages` are overridden to the `defaultProps` empty object
|
|
855
|
-
// to maintain referential equality across re-renders. It's assumed
|
|
856
|
-
// each <FormattedMessage> contains a `defaultMessage` prop.
|
|
857
|
-
config = _extends({}, config, {
|
|
858
|
-
locale: defaultLocale,
|
|
859
|
-
formats: defaultFormats,
|
|
860
|
-
messages: defaultProps.messages
|
|
861
|
-
});
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
return config;
|
|
865
|
-
}
|
|
866
|
-
}, {
|
|
867
|
-
key: 'getBoundFormatFns',
|
|
868
|
-
value: function getBoundFormatFns(config, state) {
|
|
869
|
-
return intlFormatPropNames.reduce(function (boundFormatFns, name) {
|
|
870
|
-
boundFormatFns[name] = format[name].bind(null, config, state);
|
|
871
|
-
return boundFormatFns;
|
|
872
|
-
}, {});
|
|
873
|
-
}
|
|
874
|
-
}, {
|
|
875
|
-
key: 'getChildContext',
|
|
876
|
-
value: function getChildContext() {
|
|
877
|
-
var config = this.getConfig();
|
|
798
|
+
// Creating `Intl*` formatters is expensive. If there's a parent
|
|
799
|
+
// `<IntlProvider>`, then its formatters will be used. Otherwise, this
|
|
800
|
+
// memoize the `Intl*` constructors and cache them for the lifecycle of
|
|
801
|
+
// this IntlProvider instance.
|
|
802
|
+
|
|
803
|
+
var _ref = intlContext || {},
|
|
804
|
+
_ref$formatters = _ref.formatters,
|
|
805
|
+
formatters = _ref$formatters === undefined ? {
|
|
806
|
+
getDateTimeFormat: memoizeIntlConstructor(Intl.DateTimeFormat),
|
|
807
|
+
getNumberFormat: memoizeIntlConstructor(Intl.NumberFormat),
|
|
808
|
+
getMessageFormat: memoizeIntlConstructor(IntlMessageFormat),
|
|
809
|
+
getRelativeFormat: memoizeIntlConstructor(IntlRelativeFormat),
|
|
810
|
+
getPluralFormat: memoizeIntlConstructor(IntlPluralFormat)
|
|
811
|
+
} : _ref$formatters;
|
|
812
|
+
|
|
813
|
+
_this.state = _extends({}, formatters, {
|
|
814
|
+
|
|
815
|
+
// Wrapper to provide stable "now" time for initial render.
|
|
816
|
+
now: function now() {
|
|
817
|
+
return _this._didDisplay ? Date.now() : initialNow;
|
|
818
|
+
}
|
|
819
|
+
});
|
|
820
|
+
return _this;
|
|
821
|
+
}
|
|
878
822
|
|
|
879
|
-
|
|
880
|
-
|
|
823
|
+
createClass(IntlProvider, [{
|
|
824
|
+
key: 'getConfig',
|
|
825
|
+
value: function getConfig() {
|
|
826
|
+
var intlContext = this.context.intl;
|
|
881
827
|
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
formatters = objectWithoutProperties(_state, ['now']);
|
|
828
|
+
// Build a whitelisted config object from `props`, defaults, and
|
|
829
|
+
// `context.intl`, if an <IntlProvider> exists in the ancestry.
|
|
885
830
|
|
|
831
|
+
var config = filterProps(this.props, intlConfigPropNames$1, intlContext);
|
|
886
832
|
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
833
|
+
// Apply default props. This must be applied last after the props have
|
|
834
|
+
// been resolved and inherited from any <IntlProvider> in the ancestry.
|
|
835
|
+
// This matches how React resolves `defaultProps`.
|
|
836
|
+
for (var propName in defaultProps) {
|
|
837
|
+
if (config[propName] === undefined) {
|
|
838
|
+
config[propName] = defaultProps[propName];
|
|
893
839
|
}
|
|
894
|
-
|
|
895
|
-
key: 'shouldComponentUpdate',
|
|
896
|
-
value: function shouldComponentUpdate() {
|
|
897
|
-
for (var _len = arguments.length, next = Array(_len), _key = 0; _key < _len; _key++) {
|
|
898
|
-
next[_key] = arguments[_key];
|
|
899
|
-
}
|
|
840
|
+
}
|
|
900
841
|
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
value: function render() {
|
|
911
|
-
return Children.only(this.props.children);
|
|
842
|
+
if (!hasLocaleData(config.locale)) {
|
|
843
|
+
var _config = config,
|
|
844
|
+
locale = _config.locale,
|
|
845
|
+
defaultLocale = _config.defaultLocale,
|
|
846
|
+
defaultFormats = _config.defaultFormats;
|
|
847
|
+
|
|
848
|
+
|
|
849
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
850
|
+
console.error('[React Intl] Missing locale data for locale: "' + locale + '". ' + ('Using default locale: "' + defaultLocale + '" as fallback.'));
|
|
912
851
|
}
|
|
913
|
-
|
|
914
|
-
|
|
852
|
+
|
|
853
|
+
// Since there's no registered locale data for `locale`, this will
|
|
854
|
+
// fallback to the `defaultLocale` to make sure things can render.
|
|
855
|
+
// The `messages` are overridden to the `defaultProps` empty object
|
|
856
|
+
// to maintain referential equality across re-renders. It's assumed
|
|
857
|
+
// each <FormattedMessage> contains a `defaultMessage` prop.
|
|
858
|
+
config = _extends({}, config, {
|
|
859
|
+
locale: defaultLocale,
|
|
860
|
+
formats: defaultFormats,
|
|
861
|
+
messages: defaultProps.messages
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
return config;
|
|
866
|
+
}
|
|
867
|
+
}, {
|
|
868
|
+
key: 'getBoundFormatFns',
|
|
869
|
+
value: function getBoundFormatFns(config, state) {
|
|
870
|
+
return intlFormatPropNames.reduce(function (boundFormatFns, name) {
|
|
871
|
+
boundFormatFns[name] = format[name].bind(null, config, state);
|
|
872
|
+
return boundFormatFns;
|
|
873
|
+
}, {});
|
|
874
|
+
}
|
|
875
|
+
}, {
|
|
876
|
+
key: 'getChildContext',
|
|
877
|
+
value: function getChildContext() {
|
|
878
|
+
var config = this.getConfig();
|
|
879
|
+
|
|
880
|
+
// Bind intl factories and current config to the format functions.
|
|
881
|
+
var boundFormatFns = this.getBoundFormatFns(config, this.state);
|
|
882
|
+
|
|
883
|
+
var _state = this.state,
|
|
884
|
+
now = _state.now,
|
|
885
|
+
formatters = objectWithoutProperties(_state, ['now']);
|
|
886
|
+
|
|
887
|
+
|
|
888
|
+
return {
|
|
889
|
+
intl: _extends({}, config, boundFormatFns, {
|
|
890
|
+
formatters: formatters,
|
|
891
|
+
now: now
|
|
892
|
+
})
|
|
893
|
+
};
|
|
894
|
+
}
|
|
895
|
+
}, {
|
|
896
|
+
key: 'shouldComponentUpdate',
|
|
897
|
+
value: function shouldComponentUpdate() {
|
|
898
|
+
for (var _len = arguments.length, next = Array(_len), _key = 0; _key < _len; _key++) {
|
|
899
|
+
next[_key] = arguments[_key];
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
return shouldIntlComponentUpdate.apply(undefined, [this].concat(next));
|
|
903
|
+
}
|
|
904
|
+
}, {
|
|
905
|
+
key: 'componentDidMount',
|
|
906
|
+
value: function componentDidMount() {
|
|
907
|
+
this._didDisplay = true;
|
|
908
|
+
}
|
|
909
|
+
}, {
|
|
910
|
+
key: 'render',
|
|
911
|
+
value: function render() {
|
|
912
|
+
return Children.only(this.props.children);
|
|
913
|
+
}
|
|
914
|
+
}]);
|
|
915
|
+
return IntlProvider;
|
|
915
916
|
}(Component);
|
|
916
917
|
|
|
917
918
|
IntlProvider.displayName = 'IntlProvider';
|
|
918
919
|
IntlProvider.contextTypes = {
|
|
919
|
-
|
|
920
|
+
intl: intlShape
|
|
920
921
|
};
|
|
921
922
|
IntlProvider.childContextTypes = {
|
|
922
|
-
|
|
923
|
+
intl: intlShape.isRequired
|
|
923
924
|
};
|
|
924
925
|
process.env.NODE_ENV !== "production" ? IntlProvider.propTypes = _extends({}, intlConfigPropTypes, {
|
|
925
|
-
|
|
926
|
-
|
|
926
|
+
children: PropTypes.element.isRequired,
|
|
927
|
+
initialNow: PropTypes.any
|
|
927
928
|
}) : void 0;
|
|
928
929
|
|
|
929
930
|
/*
|
|
@@ -933,61 +934,61 @@ process.env.NODE_ENV !== "production" ? IntlProvider.propTypes = _extends({}, in
|
|
|
933
934
|
*/
|
|
934
935
|
|
|
935
936
|
var FormattedDate = function (_Component) {
|
|
936
|
-
|
|
937
|
+
inherits(FormattedDate, _Component);
|
|
938
|
+
|
|
939
|
+
function FormattedDate(props, context) {
|
|
940
|
+
classCallCheck(this, FormattedDate);
|
|
937
941
|
|
|
938
|
-
|
|
939
|
-
classCallCheck(this, FormattedDate);
|
|
942
|
+
var _this = possibleConstructorReturn(this, (FormattedDate.__proto__ || Object.getPrototypeOf(FormattedDate)).call(this, props, context));
|
|
940
943
|
|
|
941
|
-
|
|
944
|
+
invariantIntlContext(context);
|
|
945
|
+
return _this;
|
|
946
|
+
}
|
|
942
947
|
|
|
943
|
-
|
|
944
|
-
|
|
948
|
+
createClass(FormattedDate, [{
|
|
949
|
+
key: 'shouldComponentUpdate',
|
|
950
|
+
value: function shouldComponentUpdate() {
|
|
951
|
+
for (var _len = arguments.length, next = Array(_len), _key = 0; _key < _len; _key++) {
|
|
952
|
+
next[_key] = arguments[_key];
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
return shouldIntlComponentUpdate.apply(undefined, [this].concat(next));
|
|
945
956
|
}
|
|
957
|
+
}, {
|
|
958
|
+
key: 'render',
|
|
959
|
+
value: function render() {
|
|
960
|
+
var _context$intl = this.context.intl,
|
|
961
|
+
formatDate = _context$intl.formatDate,
|
|
962
|
+
Text = _context$intl.textComponent;
|
|
963
|
+
var _props = this.props,
|
|
964
|
+
value = _props.value,
|
|
965
|
+
children = _props.children;
|
|
946
966
|
|
|
947
|
-
createClass(FormattedDate, [{
|
|
948
|
-
key: 'shouldComponentUpdate',
|
|
949
|
-
value: function shouldComponentUpdate() {
|
|
950
|
-
for (var _len = arguments.length, next = Array(_len), _key = 0; _key < _len; _key++) {
|
|
951
|
-
next[_key] = arguments[_key];
|
|
952
|
-
}
|
|
953
967
|
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
if (typeof children === 'function') {
|
|
970
|
-
return children(formattedDate);
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
return React.createElement(
|
|
974
|
-
Text,
|
|
975
|
-
null,
|
|
976
|
-
formattedDate
|
|
977
|
-
);
|
|
978
|
-
}
|
|
979
|
-
}]);
|
|
980
|
-
return FormattedDate;
|
|
968
|
+
var formattedDate = formatDate(value, this.props);
|
|
969
|
+
|
|
970
|
+
if (typeof children === 'function') {
|
|
971
|
+
return children(formattedDate);
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
return React.createElement(
|
|
975
|
+
Text,
|
|
976
|
+
null,
|
|
977
|
+
formattedDate
|
|
978
|
+
);
|
|
979
|
+
}
|
|
980
|
+
}]);
|
|
981
|
+
return FormattedDate;
|
|
981
982
|
}(Component);
|
|
982
983
|
|
|
983
984
|
FormattedDate.displayName = 'FormattedDate';
|
|
984
985
|
FormattedDate.contextTypes = {
|
|
985
|
-
|
|
986
|
+
intl: intlShape
|
|
986
987
|
};
|
|
987
988
|
process.env.NODE_ENV !== "production" ? FormattedDate.propTypes = _extends({}, dateTimeFormatPropTypes, {
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
989
|
+
value: PropTypes.any.isRequired,
|
|
990
|
+
format: PropTypes.string,
|
|
991
|
+
children: PropTypes.func
|
|
991
992
|
}) : void 0;
|
|
992
993
|
|
|
993
994
|
/*
|
|
@@ -997,61 +998,61 @@ process.env.NODE_ENV !== "production" ? FormattedDate.propTypes = _extends({}, d
|
|
|
997
998
|
*/
|
|
998
999
|
|
|
999
1000
|
var FormattedTime = function (_Component) {
|
|
1000
|
-
|
|
1001
|
+
inherits(FormattedTime, _Component);
|
|
1001
1002
|
|
|
1002
|
-
|
|
1003
|
-
|
|
1003
|
+
function FormattedTime(props, context) {
|
|
1004
|
+
classCallCheck(this, FormattedTime);
|
|
1004
1005
|
|
|
1005
|
-
|
|
1006
|
+
var _this = possibleConstructorReturn(this, (FormattedTime.__proto__ || Object.getPrototypeOf(FormattedTime)).call(this, props, context));
|
|
1006
1007
|
|
|
1007
|
-
|
|
1008
|
-
|
|
1008
|
+
invariantIntlContext(context);
|
|
1009
|
+
return _this;
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
createClass(FormattedTime, [{
|
|
1013
|
+
key: 'shouldComponentUpdate',
|
|
1014
|
+
value: function shouldComponentUpdate() {
|
|
1015
|
+
for (var _len = arguments.length, next = Array(_len), _key = 0; _key < _len; _key++) {
|
|
1016
|
+
next[_key] = arguments[_key];
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
return shouldIntlComponentUpdate.apply(undefined, [this].concat(next));
|
|
1009
1020
|
}
|
|
1021
|
+
}, {
|
|
1022
|
+
key: 'render',
|
|
1023
|
+
value: function render() {
|
|
1024
|
+
var _context$intl = this.context.intl,
|
|
1025
|
+
formatTime = _context$intl.formatTime,
|
|
1026
|
+
Text = _context$intl.textComponent;
|
|
1027
|
+
var _props = this.props,
|
|
1028
|
+
value = _props.value,
|
|
1029
|
+
children = _props.children;
|
|
1010
1030
|
|
|
1011
|
-
createClass(FormattedTime, [{
|
|
1012
|
-
key: 'shouldComponentUpdate',
|
|
1013
|
-
value: function shouldComponentUpdate() {
|
|
1014
|
-
for (var _len = arguments.length, next = Array(_len), _key = 0; _key < _len; _key++) {
|
|
1015
|
-
next[_key] = arguments[_key];
|
|
1016
|
-
}
|
|
1017
1031
|
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
if (typeof children === 'function') {
|
|
1034
|
-
return children(formattedTime);
|
|
1035
|
-
}
|
|
1036
|
-
|
|
1037
|
-
return React.createElement(
|
|
1038
|
-
Text,
|
|
1039
|
-
null,
|
|
1040
|
-
formattedTime
|
|
1041
|
-
);
|
|
1042
|
-
}
|
|
1043
|
-
}]);
|
|
1044
|
-
return FormattedTime;
|
|
1032
|
+
var formattedTime = formatTime(value, this.props);
|
|
1033
|
+
|
|
1034
|
+
if (typeof children === 'function') {
|
|
1035
|
+
return children(formattedTime);
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
return React.createElement(
|
|
1039
|
+
Text,
|
|
1040
|
+
null,
|
|
1041
|
+
formattedTime
|
|
1042
|
+
);
|
|
1043
|
+
}
|
|
1044
|
+
}]);
|
|
1045
|
+
return FormattedTime;
|
|
1045
1046
|
}(Component);
|
|
1046
1047
|
|
|
1047
1048
|
FormattedTime.displayName = 'FormattedTime';
|
|
1048
1049
|
FormattedTime.contextTypes = {
|
|
1049
|
-
|
|
1050
|
+
intl: intlShape
|
|
1050
1051
|
};
|
|
1051
1052
|
process.env.NODE_ENV !== "production" ? FormattedTime.propTypes = _extends({}, dateTimeFormatPropTypes, {
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1053
|
+
value: PropTypes.any.isRequired,
|
|
1054
|
+
format: PropTypes.string,
|
|
1055
|
+
children: PropTypes.func
|
|
1055
1056
|
}) : void 0;
|
|
1056
1057
|
|
|
1057
1058
|
/*
|
|
@@ -1070,179 +1071,179 @@ var DAY = 1000 * 60 * 60 * 24;
|
|
|
1070
1071
|
var MAX_TIMER_DELAY = 2147483647;
|
|
1071
1072
|
|
|
1072
1073
|
function selectUnits(delta) {
|
|
1073
|
-
|
|
1074
|
+
var absDelta = Math.abs(delta);
|
|
1074
1075
|
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1076
|
+
if (absDelta < MINUTE) {
|
|
1077
|
+
return 'second';
|
|
1078
|
+
}
|
|
1078
1079
|
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1080
|
+
if (absDelta < HOUR) {
|
|
1081
|
+
return 'minute';
|
|
1082
|
+
}
|
|
1082
1083
|
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1084
|
+
if (absDelta < DAY) {
|
|
1085
|
+
return 'hour';
|
|
1086
|
+
}
|
|
1086
1087
|
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1088
|
+
// The maximum scheduled delay will be measured in days since the maximum
|
|
1089
|
+
// timer delay is less than the number of milliseconds in 25 days.
|
|
1090
|
+
return 'day';
|
|
1090
1091
|
}
|
|
1091
1092
|
|
|
1092
1093
|
function getUnitDelay(units) {
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1094
|
+
switch (units) {
|
|
1095
|
+
case 'second':
|
|
1096
|
+
return SECOND;
|
|
1097
|
+
case 'minute':
|
|
1098
|
+
return MINUTE;
|
|
1099
|
+
case 'hour':
|
|
1100
|
+
return HOUR;
|
|
1101
|
+
case 'day':
|
|
1102
|
+
return DAY;
|
|
1103
|
+
default:
|
|
1104
|
+
return MAX_TIMER_DELAY;
|
|
1105
|
+
}
|
|
1105
1106
|
}
|
|
1106
1107
|
|
|
1107
1108
|
function isSameDate(a, b) {
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1109
|
+
if (a === b) {
|
|
1110
|
+
return true;
|
|
1111
|
+
}
|
|
1111
1112
|
|
|
1112
|
-
|
|
1113
|
-
|
|
1113
|
+
var aTime = new Date(a).getTime();
|
|
1114
|
+
var bTime = new Date(b).getTime();
|
|
1114
1115
|
|
|
1115
|
-
|
|
1116
|
+
return isFinite(aTime) && isFinite(bTime) && aTime === bTime;
|
|
1116
1117
|
}
|
|
1117
1118
|
|
|
1118
1119
|
var FormattedRelative = function (_Component) {
|
|
1119
|
-
|
|
1120
|
+
inherits(FormattedRelative, _Component);
|
|
1120
1121
|
|
|
1121
|
-
|
|
1122
|
-
|
|
1122
|
+
function FormattedRelative(props, context) {
|
|
1123
|
+
classCallCheck(this, FormattedRelative);
|
|
1123
1124
|
|
|
1124
|
-
|
|
1125
|
+
var _this = possibleConstructorReturn(this, (FormattedRelative.__proto__ || Object.getPrototypeOf(FormattedRelative)).call(this, props, context));
|
|
1125
1126
|
|
|
1126
|
-
|
|
1127
|
+
invariantIntlContext(context);
|
|
1127
1128
|
|
|
1128
|
-
|
|
1129
|
+
var now = isFinite(props.initialNow) ? Number(props.initialNow) : context.intl.now();
|
|
1129
1130
|
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1131
|
+
// `now` is stored as state so that `render()` remains a function of
|
|
1132
|
+
// props + state, instead of accessing `Date.now()` inside `render()`.
|
|
1133
|
+
_this.state = { now: now };
|
|
1134
|
+
return _this;
|
|
1135
|
+
}
|
|
1135
1136
|
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1137
|
+
createClass(FormattedRelative, [{
|
|
1138
|
+
key: 'scheduleNextUpdate',
|
|
1139
|
+
value: function scheduleNextUpdate(props, state) {
|
|
1140
|
+
var _this2 = this;
|
|
1140
1141
|
|
|
1141
|
-
|
|
1142
|
-
|
|
1142
|
+
// Cancel and pending update because we're scheduling a new update.
|
|
1143
|
+
clearTimeout(this._timer);
|
|
1143
1144
|
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1145
|
+
var value = props.value,
|
|
1146
|
+
units = props.units,
|
|
1147
|
+
updateInterval = props.updateInterval;
|
|
1147
1148
|
|
|
1148
|
-
|
|
1149
|
+
var time = new Date(value).getTime();
|
|
1149
1150
|
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1151
|
+
// If the `updateInterval` is falsy, including `0` or we don't have a
|
|
1152
|
+
// valid date, then auto updates have been turned off, so we bail and
|
|
1153
|
+
// skip scheduling an update.
|
|
1154
|
+
if (!updateInterval || !isFinite(time)) {
|
|
1155
|
+
return;
|
|
1156
|
+
}
|
|
1156
1157
|
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1158
|
+
var delta = time - state.now;
|
|
1159
|
+
var unitDelay = getUnitDelay(units || selectUnits(delta));
|
|
1160
|
+
var unitRemainder = Math.abs(delta % unitDelay);
|
|
1160
1161
|
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1162
|
+
// We want the largest possible timer delay which will still display
|
|
1163
|
+
// accurate information while reducing unnecessary re-renders. The delay
|
|
1164
|
+
// should be until the next "interesting" moment, like a tick from
|
|
1165
|
+
// "1 minute ago" to "2 minutes ago" when the delta is 120,000ms.
|
|
1166
|
+
var delay = delta < 0 ? Math.max(updateInterval, unitDelay - unitRemainder) : Math.max(updateInterval, unitRemainder);
|
|
1166
1167
|
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1168
|
+
this._timer = setTimeout(function () {
|
|
1169
|
+
_this2.setState({ now: _this2.context.intl.now() });
|
|
1170
|
+
}, delay);
|
|
1171
|
+
}
|
|
1172
|
+
}, {
|
|
1173
|
+
key: 'componentDidMount',
|
|
1174
|
+
value: function componentDidMount() {
|
|
1175
|
+
this.scheduleNextUpdate(this.props, this.state);
|
|
1176
|
+
}
|
|
1177
|
+
}, {
|
|
1178
|
+
key: 'componentWillReceiveProps',
|
|
1179
|
+
value: function componentWillReceiveProps(_ref) {
|
|
1180
|
+
var nextValue = _ref.value;
|
|
1181
|
+
|
|
1182
|
+
// When the `props.value` date changes, `state.now` needs to be updated,
|
|
1183
|
+
// and the next update can be rescheduled.
|
|
1184
|
+
if (!isSameDate(nextValue, this.props.value)) {
|
|
1185
|
+
this.setState({ now: this.context.intl.now() });
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
}, {
|
|
1189
|
+
key: 'shouldComponentUpdate',
|
|
1190
|
+
value: function shouldComponentUpdate() {
|
|
1191
|
+
for (var _len = arguments.length, next = Array(_len), _key = 0; _key < _len; _key++) {
|
|
1192
|
+
next[_key] = arguments[_key];
|
|
1193
|
+
}
|
|
1193
1194
|
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1195
|
+
return shouldIntlComponentUpdate.apply(undefined, [this].concat(next));
|
|
1196
|
+
}
|
|
1197
|
+
}, {
|
|
1198
|
+
key: 'componentWillUpdate',
|
|
1199
|
+
value: function componentWillUpdate(nextProps, nextState) {
|
|
1200
|
+
this.scheduleNextUpdate(nextProps, nextState);
|
|
1201
|
+
}
|
|
1202
|
+
}, {
|
|
1203
|
+
key: 'componentWillUnmount',
|
|
1204
|
+
value: function componentWillUnmount() {
|
|
1205
|
+
clearTimeout(this._timer);
|
|
1206
|
+
}
|
|
1207
|
+
}, {
|
|
1208
|
+
key: 'render',
|
|
1209
|
+
value: function render() {
|
|
1210
|
+
var _context$intl = this.context.intl,
|
|
1211
|
+
formatRelative = _context$intl.formatRelative,
|
|
1212
|
+
Text = _context$intl.textComponent;
|
|
1213
|
+
var _props = this.props,
|
|
1214
|
+
value = _props.value,
|
|
1215
|
+
children = _props.children;
|
|
1216
|
+
|
|
1217
|
+
|
|
1218
|
+
var formattedRelative = formatRelative(value, _extends({}, this.props, this.state));
|
|
1219
|
+
|
|
1220
|
+
if (typeof children === 'function') {
|
|
1221
|
+
return children(formattedRelative);
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
return React.createElement(
|
|
1225
|
+
Text,
|
|
1226
|
+
null,
|
|
1227
|
+
formattedRelative
|
|
1228
|
+
);
|
|
1229
|
+
}
|
|
1230
|
+
}]);
|
|
1231
|
+
return FormattedRelative;
|
|
1231
1232
|
}(Component);
|
|
1232
1233
|
|
|
1233
1234
|
FormattedRelative.displayName = 'FormattedRelative';
|
|
1234
1235
|
FormattedRelative.contextTypes = {
|
|
1235
|
-
|
|
1236
|
+
intl: intlShape
|
|
1236
1237
|
};
|
|
1237
1238
|
FormattedRelative.defaultProps = {
|
|
1238
|
-
|
|
1239
|
+
updateInterval: 1000 * 10
|
|
1239
1240
|
};
|
|
1240
1241
|
process.env.NODE_ENV !== "production" ? FormattedRelative.propTypes = _extends({}, relativeFormatPropTypes, {
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1242
|
+
value: PropTypes.any.isRequired,
|
|
1243
|
+
format: PropTypes.string,
|
|
1244
|
+
updateInterval: PropTypes.number,
|
|
1245
|
+
initialNow: PropTypes.any,
|
|
1246
|
+
children: PropTypes.func
|
|
1246
1247
|
}) : void 0;
|
|
1247
1248
|
|
|
1248
1249
|
/*
|
|
@@ -1252,61 +1253,61 @@ process.env.NODE_ENV !== "production" ? FormattedRelative.propTypes = _extends({
|
|
|
1252
1253
|
*/
|
|
1253
1254
|
|
|
1254
1255
|
var FormattedNumber = function (_Component) {
|
|
1255
|
-
|
|
1256
|
+
inherits(FormattedNumber, _Component);
|
|
1256
1257
|
|
|
1257
|
-
|
|
1258
|
-
|
|
1258
|
+
function FormattedNumber(props, context) {
|
|
1259
|
+
classCallCheck(this, FormattedNumber);
|
|
1259
1260
|
|
|
1260
|
-
|
|
1261
|
+
var _this = possibleConstructorReturn(this, (FormattedNumber.__proto__ || Object.getPrototypeOf(FormattedNumber)).call(this, props, context));
|
|
1261
1262
|
|
|
1262
|
-
|
|
1263
|
-
|
|
1263
|
+
invariantIntlContext(context);
|
|
1264
|
+
return _this;
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
createClass(FormattedNumber, [{
|
|
1268
|
+
key: 'shouldComponentUpdate',
|
|
1269
|
+
value: function shouldComponentUpdate() {
|
|
1270
|
+
for (var _len = arguments.length, next = Array(_len), _key = 0; _key < _len; _key++) {
|
|
1271
|
+
next[_key] = arguments[_key];
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
return shouldIntlComponentUpdate.apply(undefined, [this].concat(next));
|
|
1264
1275
|
}
|
|
1276
|
+
}, {
|
|
1277
|
+
key: 'render',
|
|
1278
|
+
value: function render() {
|
|
1279
|
+
var _context$intl = this.context.intl,
|
|
1280
|
+
formatNumber = _context$intl.formatNumber,
|
|
1281
|
+
Text = _context$intl.textComponent;
|
|
1282
|
+
var _props = this.props,
|
|
1283
|
+
value = _props.value,
|
|
1284
|
+
children = _props.children;
|
|
1265
1285
|
|
|
1266
|
-
createClass(FormattedNumber, [{
|
|
1267
|
-
key: 'shouldComponentUpdate',
|
|
1268
|
-
value: function shouldComponentUpdate() {
|
|
1269
|
-
for (var _len = arguments.length, next = Array(_len), _key = 0; _key < _len; _key++) {
|
|
1270
|
-
next[_key] = arguments[_key];
|
|
1271
|
-
}
|
|
1272
1286
|
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
if (typeof children === 'function') {
|
|
1289
|
-
return children(formattedNumber);
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
return React.createElement(
|
|
1293
|
-
Text,
|
|
1294
|
-
null,
|
|
1295
|
-
formattedNumber
|
|
1296
|
-
);
|
|
1297
|
-
}
|
|
1298
|
-
}]);
|
|
1299
|
-
return FormattedNumber;
|
|
1287
|
+
var formattedNumber = formatNumber(value, this.props);
|
|
1288
|
+
|
|
1289
|
+
if (typeof children === 'function') {
|
|
1290
|
+
return children(formattedNumber);
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
return React.createElement(
|
|
1294
|
+
Text,
|
|
1295
|
+
null,
|
|
1296
|
+
formattedNumber
|
|
1297
|
+
);
|
|
1298
|
+
}
|
|
1299
|
+
}]);
|
|
1300
|
+
return FormattedNumber;
|
|
1300
1301
|
}(Component);
|
|
1301
1302
|
|
|
1302
1303
|
FormattedNumber.displayName = 'FormattedNumber';
|
|
1303
1304
|
FormattedNumber.contextTypes = {
|
|
1304
|
-
|
|
1305
|
+
intl: intlShape
|
|
1305
1306
|
};
|
|
1306
1307
|
process.env.NODE_ENV !== "production" ? FormattedNumber.propTypes = _extends({}, numberFormatPropTypes, {
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1308
|
+
value: PropTypes.any.isRequired,
|
|
1309
|
+
format: PropTypes.string,
|
|
1310
|
+
children: PropTypes.func
|
|
1310
1311
|
}) : void 0;
|
|
1311
1312
|
|
|
1312
1313
|
/*
|
|
@@ -1316,73 +1317,73 @@ process.env.NODE_ENV !== "production" ? FormattedNumber.propTypes = _extends({},
|
|
|
1316
1317
|
*/
|
|
1317
1318
|
|
|
1318
1319
|
var FormattedPlural = function (_Component) {
|
|
1319
|
-
|
|
1320
|
+
inherits(FormattedPlural, _Component);
|
|
1320
1321
|
|
|
1321
|
-
|
|
1322
|
-
|
|
1322
|
+
function FormattedPlural(props, context) {
|
|
1323
|
+
classCallCheck(this, FormattedPlural);
|
|
1323
1324
|
|
|
1324
|
-
|
|
1325
|
+
var _this = possibleConstructorReturn(this, (FormattedPlural.__proto__ || Object.getPrototypeOf(FormattedPlural)).call(this, props, context));
|
|
1325
1326
|
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1327
|
+
invariantIntlContext(context);
|
|
1328
|
+
return _this;
|
|
1329
|
+
}
|
|
1329
1330
|
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1331
|
+
createClass(FormattedPlural, [{
|
|
1332
|
+
key: 'shouldComponentUpdate',
|
|
1333
|
+
value: function shouldComponentUpdate() {
|
|
1334
|
+
for (var _len = arguments.length, next = Array(_len), _key = 0; _key < _len; _key++) {
|
|
1335
|
+
next[_key] = arguments[_key];
|
|
1336
|
+
}
|
|
1336
1337
|
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1338
|
+
return shouldIntlComponentUpdate.apply(undefined, [this].concat(next));
|
|
1339
|
+
}
|
|
1340
|
+
}, {
|
|
1341
|
+
key: 'render',
|
|
1342
|
+
value: function render() {
|
|
1343
|
+
var _context$intl = this.context.intl,
|
|
1344
|
+
formatPlural = _context$intl.formatPlural,
|
|
1345
|
+
Text = _context$intl.textComponent;
|
|
1346
|
+
var _props = this.props,
|
|
1347
|
+
value = _props.value,
|
|
1348
|
+
other = _props.other,
|
|
1349
|
+
children = _props.children;
|
|
1350
|
+
|
|
1351
|
+
|
|
1352
|
+
var pluralCategory = formatPlural(value, this.props);
|
|
1353
|
+
var formattedPlural = this.props[pluralCategory] || other;
|
|
1354
|
+
|
|
1355
|
+
if (typeof children === 'function') {
|
|
1356
|
+
return children(formattedPlural);
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
return React.createElement(
|
|
1360
|
+
Text,
|
|
1361
|
+
null,
|
|
1362
|
+
formattedPlural
|
|
1363
|
+
);
|
|
1364
|
+
}
|
|
1365
|
+
}]);
|
|
1366
|
+
return FormattedPlural;
|
|
1366
1367
|
}(Component);
|
|
1367
1368
|
|
|
1368
1369
|
FormattedPlural.displayName = 'FormattedPlural';
|
|
1369
1370
|
FormattedPlural.contextTypes = {
|
|
1370
|
-
|
|
1371
|
+
intl: intlShape
|
|
1371
1372
|
};
|
|
1372
1373
|
FormattedPlural.defaultProps = {
|
|
1373
|
-
|
|
1374
|
+
style: 'cardinal'
|
|
1374
1375
|
};
|
|
1375
1376
|
process.env.NODE_ENV !== "production" ? FormattedPlural.propTypes = _extends({}, pluralFormatPropTypes, {
|
|
1376
|
-
|
|
1377
|
+
value: PropTypes.any.isRequired,
|
|
1377
1378
|
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1379
|
+
other: PropTypes.node.isRequired,
|
|
1380
|
+
zero: PropTypes.node,
|
|
1381
|
+
one: PropTypes.node,
|
|
1382
|
+
two: PropTypes.node,
|
|
1383
|
+
few: PropTypes.node,
|
|
1384
|
+
many: PropTypes.node,
|
|
1384
1385
|
|
|
1385
|
-
|
|
1386
|
+
children: PropTypes.func
|
|
1386
1387
|
}) : void 0;
|
|
1387
1388
|
|
|
1388
1389
|
/*
|
|
@@ -1392,142 +1393,142 @@ process.env.NODE_ENV !== "production" ? FormattedPlural.propTypes = _extends({},
|
|
|
1392
1393
|
*/
|
|
1393
1394
|
|
|
1394
1395
|
var FormattedMessage = function (_Component) {
|
|
1395
|
-
|
|
1396
|
+
inherits(FormattedMessage, _Component);
|
|
1396
1397
|
|
|
1397
|
-
|
|
1398
|
-
|
|
1398
|
+
function FormattedMessage(props, context) {
|
|
1399
|
+
classCallCheck(this, FormattedMessage);
|
|
1399
1400
|
|
|
1400
|
-
|
|
1401
|
+
var _this = possibleConstructorReturn(this, (FormattedMessage.__proto__ || Object.getPrototypeOf(FormattedMessage)).call(this, props, context));
|
|
1401
1402
|
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1403
|
+
invariantIntlContext(context);
|
|
1404
|
+
return _this;
|
|
1405
|
+
}
|
|
1405
1406
|
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1407
|
+
createClass(FormattedMessage, [{
|
|
1408
|
+
key: 'shouldComponentUpdate',
|
|
1409
|
+
value: function shouldComponentUpdate(nextProps) {
|
|
1410
|
+
var values = this.props.values;
|
|
1411
|
+
var nextValues = nextProps.values;
|
|
1411
1412
|
|
|
1412
1413
|
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1414
|
+
if (!shallowEquals(nextValues, values)) {
|
|
1415
|
+
return true;
|
|
1416
|
+
}
|
|
1416
1417
|
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1418
|
+
// Since `values` has already been checked, we know they're not
|
|
1419
|
+
// different, so the current `values` are carried over so the shallow
|
|
1420
|
+
// equals comparison on the other props isn't affected by the `values`.
|
|
1421
|
+
var nextPropsToCheck = _extends({}, nextProps, {
|
|
1422
|
+
values: values
|
|
1423
|
+
});
|
|
1423
1424
|
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1425
|
+
for (var _len = arguments.length, next = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
1426
|
+
next[_key - 1] = arguments[_key];
|
|
1427
|
+
}
|
|
1427
1428
|
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1429
|
+
return shouldIntlComponentUpdate.apply(undefined, [this, nextPropsToCheck].concat(next));
|
|
1430
|
+
}
|
|
1431
|
+
}, {
|
|
1432
|
+
key: 'render',
|
|
1433
|
+
value: function render() {
|
|
1434
|
+
var _context$intl = this.context.intl,
|
|
1435
|
+
formatMessage = _context$intl.formatMessage,
|
|
1436
|
+
Text = _context$intl.textComponent;
|
|
1437
|
+
var _props = this.props,
|
|
1438
|
+
id = _props.id,
|
|
1439
|
+
description = _props.description,
|
|
1440
|
+
defaultMessage = _props.defaultMessage,
|
|
1441
|
+
values = _props.values,
|
|
1442
|
+
_props$tagName = _props.tagName,
|
|
1443
|
+
Component$$1 = _props$tagName === undefined ? Text : _props$tagName,
|
|
1444
|
+
children = _props.children;
|
|
1445
|
+
|
|
1446
|
+
|
|
1447
|
+
var tokenDelimiter = void 0;
|
|
1448
|
+
var tokenizedValues = void 0;
|
|
1449
|
+
var elements = void 0;
|
|
1450
|
+
|
|
1451
|
+
var hasValues = values && Object.keys(values).length > 0;
|
|
1452
|
+
if (hasValues) {
|
|
1453
|
+
// Creates a token with a random UID that should not be guessable or
|
|
1454
|
+
// conflict with other parts of the `message` string.
|
|
1455
|
+
var uid = Math.floor(Math.random() * 0x10000000000).toString(16);
|
|
1456
|
+
|
|
1457
|
+
var generateToken = function () {
|
|
1458
|
+
var counter = 0;
|
|
1459
|
+
return function () {
|
|
1460
|
+
return 'ELEMENT-' + uid + '-' + (counter += 1);
|
|
1461
|
+
};
|
|
1462
|
+
}();
|
|
1463
|
+
|
|
1464
|
+
// Splitting with a delimiter to support IE8. When using a regex
|
|
1465
|
+
// with a capture group IE8 does not include the capture group in
|
|
1466
|
+
// the resulting array.
|
|
1467
|
+
tokenDelimiter = '@__' + uid + '__@';
|
|
1468
|
+
tokenizedValues = {};
|
|
1469
|
+
elements = {};
|
|
1470
|
+
|
|
1471
|
+
// Iterates over the `props` to keep track of any React Element
|
|
1472
|
+
// values so they can be represented by the `token` as a placeholder
|
|
1473
|
+
// when the `message` is formatted. This allows the formatted
|
|
1474
|
+
// message to then be broken-up into parts with references to the
|
|
1475
|
+
// React Elements inserted back in.
|
|
1476
|
+
Object.keys(values).forEach(function (name) {
|
|
1477
|
+
var value = values[name];
|
|
1478
|
+
|
|
1479
|
+
if (isValidElement(value)) {
|
|
1480
|
+
var token = generateToken();
|
|
1481
|
+
tokenizedValues[name] = tokenDelimiter + token + tokenDelimiter;
|
|
1482
|
+
elements[token] = value;
|
|
1483
|
+
} else {
|
|
1484
|
+
tokenizedValues[name] = value;
|
|
1485
|
+
}
|
|
1486
|
+
});
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
var descriptor = { id: id, description: description, defaultMessage: defaultMessage };
|
|
1490
|
+
var formattedMessage = formatMessage(descriptor, tokenizedValues || values);
|
|
1491
|
+
|
|
1492
|
+
var nodes = void 0;
|
|
1493
|
+
|
|
1494
|
+
var hasElements = elements && Object.keys(elements).length > 0;
|
|
1495
|
+
if (hasElements) {
|
|
1496
|
+
// Split the message into parts so the React Element values captured
|
|
1497
|
+
// above can be inserted back into the rendered message. This
|
|
1498
|
+
// approach allows messages to render with React Elements while
|
|
1499
|
+
// keeping React's virtual diffing working properly.
|
|
1500
|
+
nodes = formattedMessage.split(tokenDelimiter).filter(function (part) {
|
|
1501
|
+
return !!part;
|
|
1502
|
+
}).map(function (part) {
|
|
1503
|
+
return elements[part] || part;
|
|
1504
|
+
});
|
|
1505
|
+
} else {
|
|
1506
|
+
nodes = [formattedMessage];
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
if (typeof children === 'function') {
|
|
1510
|
+
return children.apply(undefined, toConsumableArray(nodes));
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
// Needs to use `createElement()` instead of JSX, otherwise React will
|
|
1514
|
+
// warn about a missing `key` prop with rich-text message formatting.
|
|
1515
|
+
return createElement.apply(undefined, [Component$$1, null].concat(toConsumableArray(nodes)));
|
|
1516
|
+
}
|
|
1517
|
+
}]);
|
|
1518
|
+
return FormattedMessage;
|
|
1518
1519
|
}(Component);
|
|
1519
1520
|
|
|
1520
1521
|
FormattedMessage.displayName = 'FormattedMessage';
|
|
1521
1522
|
FormattedMessage.contextTypes = {
|
|
1522
|
-
|
|
1523
|
+
intl: intlShape
|
|
1523
1524
|
};
|
|
1524
1525
|
FormattedMessage.defaultProps = {
|
|
1525
|
-
|
|
1526
|
+
values: {}
|
|
1526
1527
|
};
|
|
1527
1528
|
process.env.NODE_ENV !== "production" ? FormattedMessage.propTypes = _extends({}, messageDescriptorPropTypes, {
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1529
|
+
values: PropTypes.object,
|
|
1530
|
+
tagName: PropTypes.string,
|
|
1531
|
+
children: PropTypes.func
|
|
1531
1532
|
}) : void 0;
|
|
1532
1533
|
|
|
1533
1534
|
/*
|
|
@@ -1537,90 +1538,90 @@ process.env.NODE_ENV !== "production" ? FormattedMessage.propTypes = _extends({}
|
|
|
1537
1538
|
*/
|
|
1538
1539
|
|
|
1539
1540
|
var FormattedHTMLMessage = function (_Component) {
|
|
1540
|
-
|
|
1541
|
+
inherits(FormattedHTMLMessage, _Component);
|
|
1541
1542
|
|
|
1542
|
-
|
|
1543
|
-
|
|
1543
|
+
function FormattedHTMLMessage(props, context) {
|
|
1544
|
+
classCallCheck(this, FormattedHTMLMessage);
|
|
1544
1545
|
|
|
1545
|
-
|
|
1546
|
+
var _this = possibleConstructorReturn(this, (FormattedHTMLMessage.__proto__ || Object.getPrototypeOf(FormattedHTMLMessage)).call(this, props, context));
|
|
1546
1547
|
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1548
|
+
invariantIntlContext(context);
|
|
1549
|
+
return _this;
|
|
1550
|
+
}
|
|
1550
1551
|
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1552
|
+
createClass(FormattedHTMLMessage, [{
|
|
1553
|
+
key: 'shouldComponentUpdate',
|
|
1554
|
+
value: function shouldComponentUpdate(nextProps) {
|
|
1555
|
+
var values = this.props.values;
|
|
1556
|
+
var nextValues = nextProps.values;
|
|
1556
1557
|
|
|
1557
1558
|
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1559
|
+
if (!shallowEquals(nextValues, values)) {
|
|
1560
|
+
return true;
|
|
1561
|
+
}
|
|
1561
1562
|
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1563
|
+
// Since `values` has already been checked, we know they're not
|
|
1564
|
+
// different, so the current `values` are carried over so the shallow
|
|
1565
|
+
// equals comparison on the other props isn't affected by the `values`.
|
|
1566
|
+
var nextPropsToCheck = _extends({}, nextProps, {
|
|
1567
|
+
values: values
|
|
1568
|
+
});
|
|
1568
1569
|
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1570
|
+
for (var _len = arguments.length, next = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
1571
|
+
next[_key - 1] = arguments[_key];
|
|
1572
|
+
}
|
|
1572
1573
|
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1574
|
+
return shouldIntlComponentUpdate.apply(undefined, [this, nextPropsToCheck].concat(next));
|
|
1575
|
+
}
|
|
1576
|
+
}, {
|
|
1577
|
+
key: 'render',
|
|
1578
|
+
value: function render() {
|
|
1579
|
+
var _context$intl = this.context.intl,
|
|
1580
|
+
formatHTMLMessage = _context$intl.formatHTMLMessage,
|
|
1581
|
+
Text = _context$intl.textComponent;
|
|
1582
|
+
var _props = this.props,
|
|
1583
|
+
id = _props.id,
|
|
1584
|
+
description = _props.description,
|
|
1585
|
+
defaultMessage = _props.defaultMessage,
|
|
1586
|
+
rawValues = _props.values,
|
|
1587
|
+
_props$tagName = _props.tagName,
|
|
1588
|
+
Component$$1 = _props$tagName === undefined ? Text : _props$tagName,
|
|
1589
|
+
children = _props.children;
|
|
1590
|
+
|
|
1591
|
+
|
|
1592
|
+
var descriptor = { id: id, description: description, defaultMessage: defaultMessage };
|
|
1593
|
+
var formattedHTMLMessage = formatHTMLMessage(descriptor, rawValues);
|
|
1594
|
+
|
|
1595
|
+
if (typeof children === 'function') {
|
|
1596
|
+
return children(formattedHTMLMessage);
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
// Since the message presumably has HTML in it, we need to set
|
|
1600
|
+
// `innerHTML` in order for it to be rendered and not escaped by React.
|
|
1601
|
+
// To be safe, all string prop values were escaped when formatting the
|
|
1602
|
+
// message. It is assumed that the message is not UGC, and came from the
|
|
1603
|
+
// developer making it more like a template.
|
|
1604
|
+
//
|
|
1605
|
+
// Note: There's a perf impact of using this component since there's no
|
|
1606
|
+
// way for React to do its virtual DOM diffing.
|
|
1607
|
+
var html = { __html: formattedHTMLMessage };
|
|
1608
|
+
return React.createElement(Component$$1, { dangerouslySetInnerHTML: html });
|
|
1609
|
+
}
|
|
1610
|
+
}]);
|
|
1611
|
+
return FormattedHTMLMessage;
|
|
1611
1612
|
}(Component);
|
|
1612
1613
|
|
|
1613
1614
|
FormattedHTMLMessage.displayName = 'FormattedHTMLMessage';
|
|
1614
1615
|
FormattedHTMLMessage.contextTypes = {
|
|
1615
|
-
|
|
1616
|
+
intl: intlShape
|
|
1616
1617
|
};
|
|
1617
1618
|
FormattedHTMLMessage.defaultProps = {
|
|
1618
|
-
|
|
1619
|
+
values: {}
|
|
1619
1620
|
};
|
|
1620
1621
|
process.env.NODE_ENV !== "production" ? FormattedHTMLMessage.propTypes = _extends({}, messageDescriptorPropTypes, {
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1622
|
+
values: PropTypes.object,
|
|
1623
|
+
tagName: PropTypes.string,
|
|
1624
|
+
children: PropTypes.func
|
|
1624
1625
|
}) : void 0;
|
|
1625
1626
|
|
|
1626
1627
|
/*
|