react-intl 2.2.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +20 -0
- package/dist/react-intl.js +1017 -1475
- 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 +983 -1428
- package/lib/index.js +990 -1435
- 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 +33 -27
- package/src/components/date.js +30 -29
- package/src/components/html-message.js +63 -62
- package/src/components/message.js +117 -114
- package/src/components/number.js +30 -29
- package/src/components/plural.js +37 -36
- package/src/components/provider.js +135 -134
- package/src/components/relative.js +128 -120
- package/src/components/time.js +30 -29
- package/src/define-messages.js +3 -3
- package/src/en.js +1 -1
- package/src/format.js +209 -208
- package/src/inject.js +38 -40
- package/src/locale-data-registry.js +21 -21
- package/src/plural.js +9 -9
- package/src/types.js +58 -48
- package/src/utils.js +65 -55
- package/yarn.lock +4832 -0
package/src/plural.js
CHANGED
|
@@ -9,20 +9,20 @@
|
|
|
9
9
|
import IntlMessageFormat from 'intl-messageformat';
|
|
10
10
|
|
|
11
11
|
function resolveLocale(locales) {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
// IntlMessageFormat#_resolveLocale() does not depend on `this`.
|
|
13
|
+
return IntlMessageFormat.prototype._resolveLocale(locales);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
function findPluralFunction(locale) {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
// IntlMessageFormat#_findPluralFunction() does not depend on `this`.
|
|
18
|
+
return IntlMessageFormat.prototype._findPluralRuleFunction(locale);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export default class IntlPluralFormat {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
constructor(locales, options = {}) {
|
|
23
|
+
let useOrdinal = options.style === 'ordinal';
|
|
24
|
+
let pluralFn = findPluralFunction(resolveLocale(locales));
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
this.format = value => pluralFn(value, useOrdinal);
|
|
27
|
+
}
|
|
28
28
|
}
|
package/src/types.js
CHANGED
|
@@ -4,85 +4,95 @@
|
|
|
4
4
|
* See the accompanying LICENSE file for terms.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import
|
|
7
|
+
import PropTypes from 'prop-types';
|
|
8
8
|
|
|
9
|
-
const {
|
|
9
|
+
const {
|
|
10
|
+
bool,
|
|
11
|
+
number,
|
|
12
|
+
string,
|
|
13
|
+
func,
|
|
14
|
+
object,
|
|
15
|
+
oneOf,
|
|
16
|
+
shape,
|
|
17
|
+
any,
|
|
18
|
+
oneOfType,
|
|
19
|
+
} = PropTypes;
|
|
10
20
|
const localeMatcher = oneOf(['best fit', 'lookup']);
|
|
11
21
|
const narrowShortLong = oneOf(['narrow', 'short', 'long']);
|
|
12
22
|
const numeric2digit = oneOf(['numeric', '2-digit']);
|
|
13
23
|
const funcReq = func.isRequired;
|
|
14
24
|
|
|
15
25
|
export const intlConfigPropTypes = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
locale: string,
|
|
27
|
+
formats: object,
|
|
28
|
+
messages: object,
|
|
29
|
+
textComponent: any,
|
|
20
30
|
|
|
21
|
-
|
|
22
|
-
|
|
31
|
+
defaultLocale: string,
|
|
32
|
+
defaultFormats: object,
|
|
23
33
|
};
|
|
24
34
|
|
|
25
35
|
export const intlFormatPropTypes = {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
formatDate: funcReq,
|
|
37
|
+
formatTime: funcReq,
|
|
38
|
+
formatRelative: funcReq,
|
|
39
|
+
formatNumber: funcReq,
|
|
40
|
+
formatPlural: funcReq,
|
|
41
|
+
formatMessage: funcReq,
|
|
42
|
+
formatHTMLMessage: funcReq,
|
|
33
43
|
};
|
|
34
44
|
|
|
35
45
|
export const intlShape = shape({
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
46
|
+
...intlConfigPropTypes,
|
|
47
|
+
...intlFormatPropTypes,
|
|
48
|
+
formatters: object,
|
|
49
|
+
now: funcReq,
|
|
40
50
|
});
|
|
41
51
|
|
|
42
52
|
export const messageDescriptorPropTypes = {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
53
|
+
id: string.isRequired,
|
|
54
|
+
description: oneOfType([string, object]),
|
|
55
|
+
defaultMessage: string,
|
|
46
56
|
};
|
|
47
57
|
|
|
48
58
|
export const dateTimeFormatPropTypes = {
|
|
49
|
-
|
|
50
|
-
|
|
59
|
+
localeMatcher,
|
|
60
|
+
formatMatcher: oneOf(['basic', 'best fit']),
|
|
51
61
|
|
|
52
|
-
|
|
53
|
-
|
|
62
|
+
timeZone: string,
|
|
63
|
+
hour12: bool,
|
|
54
64
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
weekday: narrowShortLong,
|
|
66
|
+
era: narrowShortLong,
|
|
67
|
+
year: numeric2digit,
|
|
68
|
+
month: oneOf(['numeric', '2-digit', 'narrow', 'short', 'long']),
|
|
69
|
+
day: numeric2digit,
|
|
70
|
+
hour: numeric2digit,
|
|
71
|
+
minute: numeric2digit,
|
|
72
|
+
second: numeric2digit,
|
|
73
|
+
timeZoneName: oneOf(['short', 'long']),
|
|
64
74
|
};
|
|
65
75
|
|
|
66
76
|
export const numberFormatPropTypes = {
|
|
67
|
-
|
|
77
|
+
localeMatcher,
|
|
68
78
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
79
|
+
style: oneOf(['decimal', 'currency', 'percent']),
|
|
80
|
+
currency: string,
|
|
81
|
+
currencyDisplay: oneOf(['symbol', 'code', 'name']),
|
|
82
|
+
useGrouping: bool,
|
|
73
83
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
84
|
+
minimumIntegerDigits: number,
|
|
85
|
+
minimumFractionDigits: number,
|
|
86
|
+
maximumFractionDigits: number,
|
|
87
|
+
minimumSignificantDigits: number,
|
|
88
|
+
maximumSignificantDigits: number,
|
|
79
89
|
};
|
|
80
90
|
|
|
81
91
|
export const relativeFormatPropTypes = {
|
|
82
|
-
|
|
83
|
-
|
|
92
|
+
style: oneOf(['best fit', 'numeric']),
|
|
93
|
+
units: oneOf(['second', 'minute', 'hour', 'day', 'month', 'year']),
|
|
84
94
|
};
|
|
85
95
|
|
|
86
96
|
export const pluralFormatPropTypes = {
|
|
87
|
-
|
|
97
|
+
style: oneOf(['cardinal', 'ordinal']),
|
|
88
98
|
};
|
package/src/utils.js
CHANGED
|
@@ -15,79 +15,89 @@ import {intlConfigPropTypes} from './types';
|
|
|
15
15
|
const intlConfigPropNames = Object.keys(intlConfigPropTypes);
|
|
16
16
|
|
|
17
17
|
const ESCAPED_CHARS = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
'&': '&',
|
|
19
|
+
'>': '>',
|
|
20
|
+
'<': '<',
|
|
21
|
+
'"': '"',
|
|
22
|
+
"'": ''',
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
const UNSAFE_CHARS_REGEX = /[&><"']/g;
|
|
26
26
|
|
|
27
27
|
export function escape(str) {
|
|
28
|
-
|
|
28
|
+
return ('' + str).replace(UNSAFE_CHARS_REGEX, match => ESCAPED_CHARS[match]);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export function filterProps(props, whitelist, defaults = {}) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
return whitelist.reduce((filtered, name) => {
|
|
33
|
+
if (props.hasOwnProperty(name)) {
|
|
34
|
+
filtered[name] = props[name];
|
|
35
|
+
} else if (defaults.hasOwnProperty(name)) {
|
|
36
|
+
filtered[name] = defaults[name];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return filtered;
|
|
40
|
+
}, {});
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export function invariantIntlContext({intl} = {}) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
invariant(
|
|
45
|
+
intl,
|
|
46
|
+
'[React Intl] Could not find required `intl` object. ' +
|
|
47
|
+
'<IntlProvider> needs to exist in the component ancestry.'
|
|
48
|
+
);
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
export function shallowEquals(objA, objB) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
52
|
+
if (objA === objB) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (
|
|
57
|
+
typeof objA !== 'object' ||
|
|
58
|
+
objA === null ||
|
|
59
|
+
typeof objB !== 'object' ||
|
|
60
|
+
objB === null
|
|
61
|
+
) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let keysA = Object.keys(objA);
|
|
66
|
+
let keysB = Object.keys(objB);
|
|
67
|
+
|
|
68
|
+
if (keysA.length !== keysB.length) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Test for A's keys different from B.
|
|
73
|
+
let bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB);
|
|
74
|
+
for (let i = 0; i < keysA.length; i++) {
|
|
75
|
+
if (!bHasOwnProperty(keysA[i]) || objA[keysA[i]] !== objB[keysA[i]]) {
|
|
76
|
+
return false;
|
|
73
77
|
}
|
|
78
|
+
}
|
|
74
79
|
|
|
75
|
-
|
|
80
|
+
return true;
|
|
76
81
|
}
|
|
77
82
|
|
|
78
83
|
export function shouldIntlComponentUpdate(
|
|
79
|
-
|
|
80
|
-
|
|
84
|
+
{props, state, context = {}},
|
|
85
|
+
nextProps,
|
|
86
|
+
nextState,
|
|
87
|
+
nextContext = {}
|
|
81
88
|
) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
)
|
|
92
|
-
|
|
89
|
+
const {intl = {}} = context;
|
|
90
|
+
const {intl: nextIntl = {}} = nextContext;
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
!shallowEquals(nextProps, props) ||
|
|
94
|
+
!shallowEquals(nextState, state) ||
|
|
95
|
+
!(
|
|
96
|
+
nextIntl === intl ||
|
|
97
|
+
shallowEquals(
|
|
98
|
+
filterProps(nextIntl, intlConfigPropNames),
|
|
99
|
+
filterProps(intl, intlConfigPropNames)
|
|
100
|
+
)
|
|
101
|
+
)
|
|
102
|
+
);
|
|
93
103
|
}
|