react-intl 2.6.0 → 2.8.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 +60 -52
- package/dist/react-intl.js.map +1 -1
- package/dist/react-intl.min.js +1 -1
- package/dist/react-intl.min.js.map +1 -1
- package/lib/index.es.js +60 -52
- package/lib/index.js +60 -52
- 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 -1
- 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/ccp.js +1 -0
- 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/ia.js +1 -0
- 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 -1
- package/locale-data/io.js +1 -0
- 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/mi.js +1 -0
- 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 -1
- 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/sc.js +1 -0
- package/locale-data/scn.js +1 -0
- package/locale-data/sd.js +1 -0
- 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/tg.js +1 -0
- 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/tt.js +1 -0
- 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 -1
- package/locale-data/zgh.js +1 -1
- package/locale-data/zh.js +1 -1
- package/locale-data/zu.js +1 -1
- package/package.json +2 -2
- package/src/components/provider.js +16 -8
- package/src/en.js +1 -1
- package/src/format.js +55 -57
- package/src/inject.js +2 -2
- package/src/types.js +2 -0
- package/src/utils.js +11 -0
- package/yarn.lock +19 -15
package/dist/react-intl.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright
|
|
2
|
+
* Copyright 2019, Yahoo Inc.
|
|
3
3
|
* Copyrights licensed under the New BSD License.
|
|
4
4
|
* See the accompanying LICENSE file for terms.
|
|
5
5
|
*/
|
|
@@ -25,7 +25,7 @@ var defaultLocaleData = { "locale": "en", "pluralRuleFunction": function pluralR
|
|
|
25
25
|
t0 = Number(s[0]) == n,
|
|
26
26
|
n10 = t0 && s[0].slice(-1),
|
|
27
27
|
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";
|
|
28
|
-
}, "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" } } } } };
|
|
28
|
+
}, "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" } } }, "year-short": { "displayName": "yr.", "relative": { "0": "this yr.", "1": "next yr.", "-1": "last yr." }, "relativeTime": { "future": { "one": "in {0} yr.", "other": "in {0} yr." }, "past": { "one": "{0} yr. ago", "other": "{0} yr. 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" } } }, "month-short": { "displayName": "mo.", "relative": { "0": "this mo.", "1": "next mo.", "-1": "last mo." }, "relativeTime": { "future": { "one": "in {0} mo.", "other": "in {0} mo." }, "past": { "one": "{0} mo. ago", "other": "{0} mo. 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" } } }, "day-short": { "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" } } }, "hour-short": { "displayName": "hr.", "relative": { "0": "this hour" }, "relativeTime": { "future": { "one": "in {0} hr.", "other": "in {0} hr." }, "past": { "one": "{0} hr. ago", "other": "{0} hr. 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" } } }, "minute-short": { "displayName": "min.", "relative": { "0": "this minute" }, "relativeTime": { "future": { "one": "in {0} min.", "other": "in {0} min." }, "past": { "one": "{0} min. ago", "other": "{0} min. 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" } } }, "second-short": { "displayName": "sec.", "relative": { "0": "now" }, "relativeTime": { "future": { "one": "in {0} sec.", "other": "in {0} sec." }, "past": { "one": "{0} sec. ago", "other": "{0} sec. ago" } } } } };
|
|
29
29
|
|
|
30
30
|
/*
|
|
31
31
|
Copyright (c) 2014, Yahoo! Inc. All rights reserved.
|
|
@@ -2689,7 +2689,9 @@ var intlConfigPropTypes = {
|
|
|
2689
2689
|
textComponent: any,
|
|
2690
2690
|
|
|
2691
2691
|
defaultLocale: string,
|
|
2692
|
-
defaultFormats: object
|
|
2692
|
+
defaultFormats: object,
|
|
2693
|
+
|
|
2694
|
+
onError: func
|
|
2693
2695
|
};
|
|
2694
2696
|
|
|
2695
2697
|
var intlFormatPropTypes = {
|
|
@@ -2970,6 +2972,17 @@ function shouldIntlComponentUpdate(_ref2, nextProps, nextState) {
|
|
|
2970
2972
|
return !shallowEquals(nextProps, props) || !shallowEquals(nextState, state) || !(nextIntl === intl || shallowEquals(filterProps(nextIntl, intlConfigPropNames), filterProps(intl, intlConfigPropNames)));
|
|
2971
2973
|
}
|
|
2972
2974
|
|
|
2975
|
+
function createError(message, exception) {
|
|
2976
|
+
var eMsg = exception ? '\n' + exception : '';
|
|
2977
|
+
return '[React Intl] ' + message + eMsg;
|
|
2978
|
+
}
|
|
2979
|
+
|
|
2980
|
+
function defaultErrorHandler(error) {
|
|
2981
|
+
{
|
|
2982
|
+
console.error(error);
|
|
2983
|
+
}
|
|
2984
|
+
}
|
|
2985
|
+
|
|
2973
2986
|
/*
|
|
2974
2987
|
* Copyright 2015, Yahoo Inc.
|
|
2975
2988
|
* Copyrights licensed under the New BSD License.
|
|
@@ -3007,13 +3020,17 @@ function injectIntl(WrappedComponent) {
|
|
|
3007
3020
|
value: function getWrappedInstance() {
|
|
3008
3021
|
invariant_1(withRef, '[React Intl] To access the wrapped instance, ' + 'the `{withRef: true}` option must be set when calling: ' + '`injectIntl()`');
|
|
3009
3022
|
|
|
3010
|
-
return this.
|
|
3023
|
+
return this._wrappedInstance;
|
|
3011
3024
|
}
|
|
3012
3025
|
}, {
|
|
3013
3026
|
key: 'render',
|
|
3014
3027
|
value: function render() {
|
|
3028
|
+
var _this2 = this;
|
|
3029
|
+
|
|
3015
3030
|
return React__default.createElement(WrappedComponent, _extends({}, this.props, defineProperty$2({}, intlPropName, this.context.intl), {
|
|
3016
|
-
ref: withRef ?
|
|
3031
|
+
ref: withRef ? /* istanbul ignore next */function (ref) {
|
|
3032
|
+
return _this2._wrappedInstance = ref;
|
|
3033
|
+
} : null
|
|
3017
3034
|
}));
|
|
3018
3035
|
}
|
|
3019
3036
|
}]);
|
|
@@ -3240,8 +3257,7 @@ var RELATIVE_FORMAT_THRESHOLDS = {
|
|
|
3240
3257
|
minute: 60, // minutes to hour
|
|
3241
3258
|
hour: 24, // hours to day
|
|
3242
3259
|
day: 30, // days to month
|
|
3243
|
-
month: 12
|
|
3244
|
-
};
|
|
3260
|
+
month: 12 };
|
|
3245
3261
|
|
|
3246
3262
|
function updateRelativeFormatThresholds(newThresholds) {
|
|
3247
3263
|
var thresholds = RelativeFormat.thresholds;
|
|
@@ -3257,15 +3273,13 @@ function updateRelativeFormatThresholds(newThresholds) {
|
|
|
3257
3273
|
thresholds['month-short'] = newThresholds['month-short'];
|
|
3258
3274
|
}
|
|
3259
3275
|
|
|
3260
|
-
function getNamedFormat(formats, type, name) {
|
|
3276
|
+
function getNamedFormat(formats, type, name, onError) {
|
|
3261
3277
|
var format = formats && formats[type] && formats[type][name];
|
|
3262
3278
|
if (format) {
|
|
3263
3279
|
return format;
|
|
3264
3280
|
}
|
|
3265
3281
|
|
|
3266
|
-
|
|
3267
|
-
console.error('[React Intl] No ' + type + ' format named: ' + name);
|
|
3268
|
-
}
|
|
3282
|
+
onError(createError('No ' + type + ' format named: ' + name));
|
|
3269
3283
|
}
|
|
3270
3284
|
|
|
3271
3285
|
function formatDate(config, state, value) {
|
|
@@ -3276,16 +3290,15 @@ function formatDate(config, state, value) {
|
|
|
3276
3290
|
var format = options.format;
|
|
3277
3291
|
|
|
3278
3292
|
|
|
3293
|
+
var onError = config.onError || defaultErrorHandler;
|
|
3279
3294
|
var date = new Date(value);
|
|
3280
|
-
var defaults$$1 = _extends({}, timeZone && { timeZone: timeZone }, format && getNamedFormat(formats, 'date', format));
|
|
3295
|
+
var defaults$$1 = _extends({}, timeZone && { timeZone: timeZone }, format && getNamedFormat(formats, 'date', format, onError));
|
|
3281
3296
|
var filteredOptions = filterProps(options, DATE_TIME_FORMAT_OPTIONS, defaults$$1);
|
|
3282
3297
|
|
|
3283
3298
|
try {
|
|
3284
3299
|
return state.getDateTimeFormat(locale, filteredOptions).format(date);
|
|
3285
3300
|
} catch (e) {
|
|
3286
|
-
|
|
3287
|
-
console.error('[React Intl] Error formatting date.\n' + e);
|
|
3288
|
-
}
|
|
3301
|
+
onError(createError('Error formatting date.', e));
|
|
3289
3302
|
}
|
|
3290
3303
|
|
|
3291
3304
|
return String(date);
|
|
@@ -3299,8 +3312,9 @@ function formatTime(config, state, value) {
|
|
|
3299
3312
|
var format = options.format;
|
|
3300
3313
|
|
|
3301
3314
|
|
|
3315
|
+
var onError = config.onError || defaultErrorHandler;
|
|
3302
3316
|
var date = new Date(value);
|
|
3303
|
-
var defaults$$1 = _extends({}, timeZone && { timeZone: timeZone }, format && getNamedFormat(formats, 'time', format));
|
|
3317
|
+
var defaults$$1 = _extends({}, timeZone && { timeZone: timeZone }, format && getNamedFormat(formats, 'time', format, onError));
|
|
3304
3318
|
var filteredOptions = filterProps(options, DATE_TIME_FORMAT_OPTIONS, defaults$$1);
|
|
3305
3319
|
|
|
3306
3320
|
if (!filteredOptions.hour && !filteredOptions.minute && !filteredOptions.second) {
|
|
@@ -3311,9 +3325,7 @@ function formatTime(config, state, value) {
|
|
|
3311
3325
|
try {
|
|
3312
3326
|
return state.getDateTimeFormat(locale, filteredOptions).format(date);
|
|
3313
3327
|
} catch (e) {
|
|
3314
|
-
|
|
3315
|
-
console.error('[React Intl] Error formatting time.\n' + e);
|
|
3316
|
-
}
|
|
3328
|
+
onError(createError('Error formatting time.', e));
|
|
3317
3329
|
}
|
|
3318
3330
|
|
|
3319
3331
|
return String(date);
|
|
@@ -3326,9 +3338,10 @@ function formatRelative(config, state, value) {
|
|
|
3326
3338
|
var format = options.format;
|
|
3327
3339
|
|
|
3328
3340
|
|
|
3341
|
+
var onError = config.onError || defaultErrorHandler;
|
|
3329
3342
|
var date = new Date(value);
|
|
3330
3343
|
var now = new Date(options.now);
|
|
3331
|
-
var defaults$$1 = format && getNamedFormat(formats, 'relative', format);
|
|
3344
|
+
var defaults$$1 = format && getNamedFormat(formats, 'relative', format, onError);
|
|
3332
3345
|
var filteredOptions = filterProps(options, RELATIVE_FORMAT_OPTIONS, defaults$$1);
|
|
3333
3346
|
|
|
3334
3347
|
// Capture the current threshold values, then temporarily override them with
|
|
@@ -3341,9 +3354,7 @@ function formatRelative(config, state, value) {
|
|
|
3341
3354
|
now: isFinite(now) ? now : state.now()
|
|
3342
3355
|
});
|
|
3343
3356
|
} catch (e) {
|
|
3344
|
-
|
|
3345
|
-
console.error('[React Intl] Error formatting relative time.\n' + e);
|
|
3346
|
-
}
|
|
3357
|
+
onError(createError('Error formatting relative time.', e));
|
|
3347
3358
|
} finally {
|
|
3348
3359
|
updateRelativeFormatThresholds(oldThresholds);
|
|
3349
3360
|
}
|
|
@@ -3358,15 +3369,14 @@ function formatNumber(config, state, value) {
|
|
|
3358
3369
|
var format = options.format;
|
|
3359
3370
|
|
|
3360
3371
|
|
|
3361
|
-
var
|
|
3372
|
+
var onError = config.onError || defaultErrorHandler;
|
|
3373
|
+
var defaults$$1 = format && getNamedFormat(formats, 'number', format, onError);
|
|
3362
3374
|
var filteredOptions = filterProps(options, NUMBER_FORMAT_OPTIONS, defaults$$1);
|
|
3363
3375
|
|
|
3364
3376
|
try {
|
|
3365
3377
|
return state.getNumberFormat(locale, filteredOptions).format(value);
|
|
3366
3378
|
} catch (e) {
|
|
3367
|
-
|
|
3368
|
-
console.error('[React Intl] Error formatting number.\n' + e);
|
|
3369
|
-
}
|
|
3379
|
+
onError(createError('Error formatting number.', e));
|
|
3370
3380
|
}
|
|
3371
3381
|
|
|
3372
3382
|
return String(value);
|
|
@@ -3378,13 +3388,12 @@ function formatPlural(config, state, value) {
|
|
|
3378
3388
|
|
|
3379
3389
|
|
|
3380
3390
|
var filteredOptions = filterProps(options, PLURAL_FORMAT_OPTIONS);
|
|
3391
|
+
var onError = config.onError || defaultErrorHandler;
|
|
3381
3392
|
|
|
3382
3393
|
try {
|
|
3383
3394
|
return state.getPluralFormat(locale, filteredOptions).format(value);
|
|
3384
3395
|
} catch (e) {
|
|
3385
|
-
|
|
3386
|
-
console.error('[React Intl] Error formatting plural.\n' + e);
|
|
3387
|
-
}
|
|
3396
|
+
onError(createError('Error formatting plural.', e));
|
|
3388
3397
|
}
|
|
3389
3398
|
|
|
3390
3399
|
return 'other';
|
|
@@ -3401,8 +3410,13 @@ function formatMessage(config, state) {
|
|
|
3401
3410
|
var id = messageDescriptor.id,
|
|
3402
3411
|
defaultMessage = messageDescriptor.defaultMessage;
|
|
3403
3412
|
|
|
3404
|
-
//
|
|
3413
|
+
// Produce a better error if the user calls `intl.formatMessage(element)`
|
|
3414
|
+
|
|
3415
|
+
{
|
|
3416
|
+
invariant_1(!React.isValidElement(config), '[React Intl] Don\'t pass React elements to ' + 'formatMessage(), pass `.props`.');
|
|
3417
|
+
}
|
|
3405
3418
|
|
|
3419
|
+
// `id` is a required field of a Message Descriptor.
|
|
3406
3420
|
invariant_1(id, '[React Intl] An `id` must be provided to format a message.');
|
|
3407
3421
|
|
|
3408
3422
|
var message = messages && messages[id];
|
|
@@ -3415,6 +3429,7 @@ function formatMessage(config, state) {
|
|
|
3415
3429
|
}
|
|
3416
3430
|
|
|
3417
3431
|
var formattedMessage = void 0;
|
|
3432
|
+
var onError = config.onError || defaultErrorHandler;
|
|
3418
3433
|
|
|
3419
3434
|
if (message) {
|
|
3420
3435
|
try {
|
|
@@ -3422,18 +3437,14 @@ function formatMessage(config, state) {
|
|
|
3422
3437
|
|
|
3423
3438
|
formattedMessage = formatter.format(values);
|
|
3424
3439
|
} catch (e) {
|
|
3425
|
-
|
|
3426
|
-
console.error('[React Intl] Error formatting message: "' + id + '" for locale: "' + locale + '"' + (defaultMessage ? ', using default message as fallback.' : '') + ('\n' + e));
|
|
3427
|
-
}
|
|
3440
|
+
onError(createError('Error formatting message: "' + id + '" for locale: "' + locale + '"' + (defaultMessage ? ', using default message as fallback.' : ''), e));
|
|
3428
3441
|
}
|
|
3429
3442
|
} else {
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
console.error('[React Intl] Missing message: "' + id + '" for locale: "' + locale + '"' + (defaultMessage ? ', using default message as fallback.' : ''));
|
|
3436
|
-
}
|
|
3443
|
+
// This prevents warnings from littering the console in development
|
|
3444
|
+
// when no `messages` are passed into the <IntlProvider> for the
|
|
3445
|
+
// default locale, and a default message is in the source.
|
|
3446
|
+
if (!defaultMessage || locale && locale.toLowerCase() !== defaultLocale.toLowerCase()) {
|
|
3447
|
+
onError(createError('Missing message: "' + id + '" for locale: "' + locale + '"' + (defaultMessage ? ', using default message as fallback.' : '')));
|
|
3437
3448
|
}
|
|
3438
3449
|
}
|
|
3439
3450
|
|
|
@@ -3443,16 +3454,12 @@ function formatMessage(config, state) {
|
|
|
3443
3454
|
|
|
3444
3455
|
formattedMessage = _formatter.format(values);
|
|
3445
3456
|
} catch (e) {
|
|
3446
|
-
|
|
3447
|
-
console.error('[React Intl] Error formatting the default message for: "' + id + '"' + ('\n' + e));
|
|
3448
|
-
}
|
|
3457
|
+
onError(createError('Error formatting the default message for: "' + id + '"', e));
|
|
3449
3458
|
}
|
|
3450
3459
|
}
|
|
3451
3460
|
|
|
3452
3461
|
if (!formattedMessage) {
|
|
3453
|
-
|
|
3454
|
-
console.error('[React Intl] Cannot format message: "' + id + '", ' + ('using message ' + (message || defaultMessage ? 'source' : 'id') + ' as fallback.'));
|
|
3455
|
-
}
|
|
3462
|
+
onError(createError('Cannot format message: "' + id + '", ' + ('using message ' + (message || defaultMessage ? 'source' : 'id') + ' as fallback.')));
|
|
3456
3463
|
}
|
|
3457
3464
|
|
|
3458
3465
|
return formattedMessage || message || defaultMessage || id;
|
|
@@ -3503,7 +3510,9 @@ var defaultProps = {
|
|
|
3503
3510
|
textComponent: 'span',
|
|
3504
3511
|
|
|
3505
3512
|
defaultLocale: 'en',
|
|
3506
|
-
defaultFormats: {}
|
|
3513
|
+
defaultFormats: {},
|
|
3514
|
+
|
|
3515
|
+
onError: defaultErrorHandler
|
|
3507
3516
|
};
|
|
3508
3517
|
|
|
3509
3518
|
var IntlProvider = function (_Component) {
|
|
@@ -3580,12 +3589,11 @@ var IntlProvider = function (_Component) {
|
|
|
3580
3589
|
var _config = config,
|
|
3581
3590
|
locale = _config.locale,
|
|
3582
3591
|
defaultLocale = _config.defaultLocale,
|
|
3583
|
-
defaultFormats = _config.defaultFormats
|
|
3592
|
+
defaultFormats = _config.defaultFormats,
|
|
3593
|
+
onError = _config.onError;
|
|
3584
3594
|
|
|
3585
3595
|
|
|
3586
|
-
|
|
3587
|
-
console.error('[React Intl] Missing locale data for locale: "' + locale + '". ' + ('Using default locale: "' + defaultLocale + '" as fallback.'));
|
|
3588
|
-
}
|
|
3596
|
+
onError(createError('Missing locale data for locale: "' + locale + '". ' + ('Using default locale: "' + defaultLocale + '" as fallback.')));
|
|
3589
3597
|
|
|
3590
3598
|
// Since there's no registered locale data for `locale`, this will
|
|
3591
3599
|
// fallback to the `defaultLocale` to make sure things can render.
|