react-intl 3.9.3 → 3.12.1
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/CHANGELOG.md +34 -1
- package/dist/components/createFormattedComponent.d.ts +2 -1
- package/dist/components/createFormattedComponent.js +7 -2
- package/dist/components/html-message.js +1 -1
- package/dist/components/injectIntl.d.ts +1 -1
- package/dist/components/message.js +13 -4
- package/dist/components/plural.d.ts +1 -1
- package/dist/components/provider.js +14 -9
- package/dist/components/relative.js +3 -10
- package/dist/formatters/dateTime.js +2 -2
- package/dist/formatters/displayName.d.ts +2 -0
- package/dist/formatters/displayName.js +25 -0
- package/dist/formatters/message.d.ts +1 -0
- package/dist/formatters/message.js +19 -18
- package/dist/index.d.ts +7 -3
- package/dist/index.js +5 -2
- package/dist/react-intl.api.md +22 -5
- package/dist/react-intl.d.ts +64 -15
- package/dist/react-intl.js +5821 -5655
- 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/dist/types.d.ts +6 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +5 -7
- package/lib/components/createFormattedComponent.d.ts +2 -1
- package/lib/components/createFormattedComponent.js +7 -2
- package/lib/components/html-message.js +1 -1
- package/lib/components/injectIntl.d.ts +1 -1
- package/lib/components/message.js +5 -3
- package/lib/components/plural.d.ts +1 -1
- package/lib/components/provider.js +14 -9
- package/lib/components/relative.js +3 -10
- package/lib/formatters/dateTime.js +2 -2
- package/lib/formatters/displayName.d.ts +2 -0
- package/lib/formatters/displayName.js +22 -0
- package/lib/formatters/message.d.ts +1 -0
- package/lib/formatters/message.js +12 -18
- package/lib/index.d.ts +7 -3
- package/lib/index.js +4 -1
- package/lib/react-intl.d.ts +20 -7
- package/lib/tsdoc-metadata.json +1 -1
- package/lib/types.d.ts +6 -1
- package/lib/utils.d.ts +1 -1
- package/lib/utils.js +4 -6
- package/package.json +38 -39
- package/src/components/createFormattedComponent.tsx +5 -0
- package/src/components/provider.tsx +26 -11
- package/src/components/relative.tsx +6 -15
- package/src/formatters/displayName.ts +35 -0
- package/src/formatters/message.ts +13 -18
- package/src/index.ts +7 -1
- package/src/types.ts +16 -5
- package/src/utils.ts +5 -7
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,40 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
-
### [3.
|
|
5
|
+
### [3.12.1](https://github.com/formatjs/react-intl/compare/v3.12.0...v3.12.1) (2020-03-04)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* clarify err messages ([b207d80](https://github.com/formatjs/react-intl/commit/b207d805a9e5609983ac1b2ca8f9708030e12337))
|
|
11
|
+
* inline defineMessages macro, fix [#1592](https://github.com/formatjs/react-intl/issues/1592) ([5ae8349](https://github.com/formatjs/react-intl/commit/5ae8349dc2ee08b54a54a2a521b8a9c052960d04))
|
|
12
|
+
|
|
13
|
+
## [3.12.0](https://github.com/formatjs/react-intl/compare/v3.11.0...v3.12.0) (2020-02-04)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* add formatDisplayName and FormattedDisplayName ([#1567](https://github.com/formatjs/react-intl/issues/1567)) ([10bcbe2](https://github.com/formatjs/react-intl/commit/10bcbe2e7e92902d60810a7c00568d3043b09db3)), closes [#1547](https://github.com/formatjs/react-intl/issues/1547)
|
|
19
|
+
|
|
20
|
+
## [3.11.0](https://github.com/formatjs/react-intl/compare/v3.10.0...v3.11.0) (2020-01-09)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Features
|
|
24
|
+
|
|
25
|
+
* Allow MessageDescriptor ID to be `number` ([#1553](https://github.com/formatjs/react-intl/issues/1553)) ([95298b2](https://github.com/formatjs/react-intl/commit/95298b2b5f09173258fe9648d49fc9fa1ad673fc))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Bug Fixes
|
|
29
|
+
|
|
30
|
+
* add a parser for chunks emitted from formatHTMLMessage ([#1550](https://github.com/formatjs/react-intl/issues/1550)) ([8c3c5c7](https://github.com/formatjs/react-intl/commit/8c3c5c78afa16d605933c82571f3b92b15363c27))
|
|
31
|
+
* update formatjs deps ([1745c21](https://github.com/formatjs/react-intl/commit/1745c21b9ae5e6443f1ad5209f77cc9cb6ad66eb))
|
|
32
|
+
|
|
33
|
+
## [3.10.0](https://github.com/formatjs/react-intl/compare/v3.9.2...v3.10.0) (2019-12-26)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### Features
|
|
37
|
+
|
|
38
|
+
* Upgrade intl-unified-numberformat & TypeScript ([ddf411a](https://github.com/formatjs/react-intl/commit/ddf411a6089005671f3d1ab8d11e04564da0f2e7))
|
|
6
39
|
|
|
7
40
|
### [3.9.2](https://github.com/formatjs/react-intl/compare/v3.9.1...v3.9.2) (2019-12-10)
|
|
8
41
|
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { IntlShape, FormatDateOptions, FormatNumberOptions, FormatListOptions } from '../types';
|
|
2
|
+
import { IntlShape, FormatDateOptions, FormatNumberOptions, FormatListOptions, FormatDisplayNameOptions } from '../types';
|
|
3
3
|
declare type Formatter = {
|
|
4
4
|
formatDate: FormatDateOptions;
|
|
5
5
|
formatTime: FormatDateOptions;
|
|
6
6
|
formatNumber: FormatNumberOptions;
|
|
7
7
|
formatList: FormatListOptions;
|
|
8
|
+
formatDisplayName: FormatDisplayNameOptions;
|
|
8
9
|
};
|
|
9
10
|
export declare const FormattedNumberParts: React.FC<Formatter['formatNumber'] & {
|
|
10
11
|
value: Parameters<IntlShape['formatNumber']>[0];
|
|
@@ -4,8 +4,10 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
4
4
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
5
|
t[p] = s[p];
|
|
6
6
|
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++)
|
|
8
|
-
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
9
11
|
return t;
|
|
10
12
|
};
|
|
11
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -18,6 +20,9 @@ var DisplayName;
|
|
|
18
20
|
DisplayName["formatTime"] = "FormattedTime";
|
|
19
21
|
DisplayName["formatNumber"] = "FormattedNumber";
|
|
20
22
|
DisplayName["formatList"] = "FormattedList";
|
|
23
|
+
// Note that this DisplayName is the locale display name, not to be confused with
|
|
24
|
+
// the name of the enum, which is for React component display name in dev tools.
|
|
25
|
+
DisplayName["formatDisplayName"] = "FormattedDisplayName";
|
|
21
26
|
})(DisplayName || (DisplayName = {}));
|
|
22
27
|
var DisplayNameParts;
|
|
23
28
|
(function (DisplayNameParts) {
|
|
@@ -69,7 +69,7 @@ var FormattedHTMLMessage = /** @class */ (function (_super) {
|
|
|
69
69
|
}));
|
|
70
70
|
};
|
|
71
71
|
FormattedHTMLMessage.displayName = 'FormattedHTMLMessage';
|
|
72
|
-
FormattedHTMLMessage.defaultProps = __assign({}, message_1.default.defaultProps, { tagName: 'span' });
|
|
72
|
+
FormattedHTMLMessage.defaultProps = __assign(__assign({}, message_1.default.defaultProps), { tagName: 'span' });
|
|
73
73
|
return FormattedHTMLMessage;
|
|
74
74
|
}(message_1.default));
|
|
75
75
|
exports.default = FormattedHTMLMessage;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { IntlShape, Omit } from '../types';
|
|
3
|
-
export declare const Provider: React.
|
|
3
|
+
export declare const Provider: React.Provider<IntlShape>;
|
|
4
4
|
export declare const Context: React.Context<IntlShape>;
|
|
5
5
|
export interface Opts<IntlPropName extends string = 'intl', ForwardRef extends boolean = false> {
|
|
6
6
|
intlPropName?: IntlPropName;
|
|
@@ -33,10 +33,19 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
33
33
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
34
34
|
t[p] = s[p];
|
|
35
35
|
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
36
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++)
|
|
37
|
-
|
|
36
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
37
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
38
|
+
t[p[i]] = s[p[i]];
|
|
39
|
+
}
|
|
38
40
|
return t;
|
|
39
41
|
};
|
|
42
|
+
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
43
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
44
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
45
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
46
|
+
r[k] = a[j];
|
|
47
|
+
return r;
|
|
48
|
+
};
|
|
40
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
50
|
var React = require("react");
|
|
42
51
|
var injectIntl_1 = require("./injectIntl");
|
|
@@ -48,7 +57,7 @@ var defaultFormatMessage = function (descriptor, values) {
|
|
|
48
57
|
if (process.env.NODE_ENV !== 'production') {
|
|
49
58
|
console.error('[React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry. Using default message as fallback.');
|
|
50
59
|
}
|
|
51
|
-
return message_1.formatMessage(__assign({}, utils_1.DEFAULT_INTL_CONFIG, { locale: 'en' }), utils_1.createFormatters(), descriptor, values);
|
|
60
|
+
return message_1.formatMessage(__assign(__assign({}, utils_1.DEFAULT_INTL_CONFIG), { locale: 'en' }), utils_1.createFormatters(), descriptor, values);
|
|
52
61
|
};
|
|
53
62
|
var FormattedMessage = /** @class */ (function (_super) {
|
|
54
63
|
__extends(FormattedMessage, _super);
|
|
@@ -80,7 +89,7 @@ var FormattedMessage = /** @class */ (function (_super) {
|
|
|
80
89
|
if (Component) {
|
|
81
90
|
// Needs to use `createElement()` instead of JSX, otherwise React will
|
|
82
91
|
// warn about a missing `key` prop with rich-text message formatting.
|
|
83
|
-
return React.createElement.apply(React, [Component, null]
|
|
92
|
+
return React.createElement.apply(React, __spreadArrays([Component, null], nodes));
|
|
84
93
|
}
|
|
85
94
|
return nodes;
|
|
86
95
|
}));
|
|
@@ -11,7 +11,7 @@ interface Props extends FormatPluralOptions {
|
|
|
11
11
|
many?: React.ReactNode;
|
|
12
12
|
children?(value: React.ReactNode): React.ReactElement | null;
|
|
13
13
|
}
|
|
14
|
-
declare const _default: React.ForwardRefExoticComponent<Pick<Props, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "localeMatcher" | "
|
|
14
|
+
declare const _default: React.ForwardRefExoticComponent<Pick<Props, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "localeMatcher" | "format" | "type" | "value"> & {
|
|
15
15
|
forwardedRef?: ((instance: any) => void) | React.RefObject<any> | null | undefined;
|
|
16
16
|
} & React.RefAttributes<any>> & {
|
|
17
17
|
WrappedComponent: React.ComponentType<Props>;
|
|
@@ -32,7 +32,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
32
32
|
var React = require("react");
|
|
33
33
|
var injectIntl_1 = require("./injectIntl");
|
|
34
34
|
var utils_1 = require("../utils");
|
|
35
|
-
var intl_locales_supported_1 = require("intl-locales-supported");
|
|
36
35
|
var number_1 = require("../formatters/number");
|
|
37
36
|
var relativeTime_1 = require("../formatters/relativeTime");
|
|
38
37
|
var dateTime_1 = require("../formatters/dateTime");
|
|
@@ -40,6 +39,7 @@ var plural_1 = require("../formatters/plural");
|
|
|
40
39
|
var message_1 = require("../formatters/message");
|
|
41
40
|
var shallowEquals_ = require("shallow-equal/objects");
|
|
42
41
|
var list_1 = require("../formatters/list");
|
|
42
|
+
var displayName_1 = require("../formatters/displayName");
|
|
43
43
|
var shallowEquals = shallowEquals_.default || shallowEquals_;
|
|
44
44
|
function processIntlConfig(config) {
|
|
45
45
|
return {
|
|
@@ -60,13 +60,11 @@ function processIntlConfig(config) {
|
|
|
60
60
|
*/
|
|
61
61
|
function createIntl(config, cache) {
|
|
62
62
|
var formatters = utils_1.createFormatters(cache);
|
|
63
|
-
var resolvedConfig = __assign({}, utils_1.DEFAULT_INTL_CONFIG, config);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
onError(utils_1.createError("Missing locale data for locale: \"" + locale + "\". " +
|
|
69
|
-
("Using default locale: \"" + defaultLocale + "\" as fallback.")));
|
|
63
|
+
var resolvedConfig = __assign(__assign({}, utils_1.DEFAULT_INTL_CONFIG), config);
|
|
64
|
+
var locale = resolvedConfig.locale, defaultLocale = resolvedConfig.defaultLocale, onError = resolvedConfig.onError;
|
|
65
|
+
if (!locale) {
|
|
66
|
+
if (onError) {
|
|
67
|
+
onError(utils_1.createError("\"locale\" was not configured, using \"" + defaultLocale + "\" as fallback. See https://github.com/formatjs/react-intl/blob/master/docs/API.md#intlshape for more details"));
|
|
70
68
|
}
|
|
71
69
|
// Since there's no registered locale data for `locale`, this will
|
|
72
70
|
// fallback to the `defaultLocale` to make sure things can render.
|
|
@@ -75,7 +73,14 @@ function createIntl(config, cache) {
|
|
|
75
73
|
// each <FormattedMessage> contains a `defaultMessage` prop.
|
|
76
74
|
resolvedConfig.locale = resolvedConfig.defaultLocale || 'en';
|
|
77
75
|
}
|
|
78
|
-
|
|
76
|
+
else if (!Intl.NumberFormat.supportedLocalesOf(locale).length && onError) {
|
|
77
|
+
onError(utils_1.createError("Missing locale data for locale: \"" + locale + "\" in Intl.NumberFormat. Using default locale: \"" + defaultLocale + "\" as fallback. See https://github.com/formatjs/react-intl/blob/master/docs/Getting-Started.md#runtime-requirements for more details"));
|
|
78
|
+
}
|
|
79
|
+
else if (!Intl.DateTimeFormat.supportedLocalesOf(locale).length &&
|
|
80
|
+
onError) {
|
|
81
|
+
onError(utils_1.createError("Missing locale data for locale: \"" + locale + "\" in Intl.DateTimeFormat. Using default locale: \"" + defaultLocale + "\" as fallback. See https://github.com/formatjs/react-intl/blob/master/docs/Getting-Started.md#runtime-requirements for more details"));
|
|
82
|
+
}
|
|
83
|
+
return __assign(__assign({}, resolvedConfig), { formatters: formatters, formatNumber: number_1.formatNumber.bind(null, resolvedConfig, formatters.getNumberFormat), formatNumberToParts: number_1.formatNumberToParts.bind(null, resolvedConfig, formatters.getNumberFormat), formatRelativeTime: relativeTime_1.formatRelativeTime.bind(null, resolvedConfig, formatters.getRelativeTimeFormat), formatDate: dateTime_1.formatDate.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatDateToParts: dateTime_1.formatDateToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTime: dateTime_1.formatTime.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTimeToParts: dateTime_1.formatTimeToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatPlural: plural_1.formatPlural.bind(null, resolvedConfig, formatters.getPluralRules), formatMessage: message_1.formatMessage.bind(null, resolvedConfig, formatters), formatHTMLMessage: message_1.formatHTMLMessage.bind(null, resolvedConfig, formatters), formatList: list_1.formatList.bind(null, resolvedConfig, formatters.getListFormat), formatDisplayName: displayName_1.formatDisplayName.bind(null, resolvedConfig, formatters.getDisplayNames) });
|
|
79
84
|
}
|
|
80
85
|
exports.createIntl = createIntl;
|
|
81
86
|
var IntlProvider = /** @class */ (function (_super) {
|
|
@@ -32,12 +32,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
32
32
|
var React = require("react");
|
|
33
33
|
var injectIntl_1 = require("./injectIntl");
|
|
34
34
|
var utils_1 = require("../utils");
|
|
35
|
-
|
|
36
|
-
// this is to interop with TypeScript since `invariant`
|
|
37
|
-
// does not export a default
|
|
38
|
-
// https://github.com/rollup/rollup/issues/1267
|
|
39
|
-
var invariant_ = require("invariant");
|
|
40
|
-
var invariant = invariant_.default || invariant_;
|
|
35
|
+
var intl_utils_1 = require("@formatjs/intl-utils");
|
|
41
36
|
var MINUTE = 60;
|
|
42
37
|
var HOUR = 60 * 60;
|
|
43
38
|
var DAY = 60 * 60 * 24;
|
|
@@ -84,9 +79,6 @@ function canIncrement(unit) {
|
|
|
84
79
|
if (unit === void 0) { unit = 'second'; }
|
|
85
80
|
return INCREMENTABLE_UNITS.includes(unit);
|
|
86
81
|
}
|
|
87
|
-
function verifyProps(updateIntervalInSeconds, unit) {
|
|
88
|
-
invariant(!updateIntervalInSeconds || (updateIntervalInSeconds && canIncrement(unit)), 'Cannot schedule update with unit longer than hour');
|
|
89
|
-
}
|
|
90
82
|
var FormattedRelativeTime = /** @class */ (function (_super) {
|
|
91
83
|
__extends(FormattedRelativeTime, _super);
|
|
92
84
|
function FormattedRelativeTime(props) {
|
|
@@ -100,7 +92,8 @@ var FormattedRelativeTime = /** @class */ (function (_super) {
|
|
|
100
92
|
? valueToSeconds(_this.props.value, _this.props.unit)
|
|
101
93
|
: 0,
|
|
102
94
|
};
|
|
103
|
-
|
|
95
|
+
intl_utils_1.invariant(!props.updateIntervalInSeconds ||
|
|
96
|
+
!!(props.updateIntervalInSeconds && canIncrement(props.unit)), 'Cannot schedule update with unit longer than hour');
|
|
104
97
|
return _this;
|
|
105
98
|
}
|
|
106
99
|
FormattedRelativeTime.prototype.scheduleNextUpdate = function (_a, _b) {
|
|
@@ -36,14 +36,14 @@ function getFormatter(_a, type, getDateTimeFormat, options) {
|
|
|
36
36
|
var locale = _a.locale, formats = _a.formats, onError = _a.onError, timeZone = _a.timeZone;
|
|
37
37
|
if (options === void 0) { options = {}; }
|
|
38
38
|
var format = options.format;
|
|
39
|
-
var defaults = __assign({}, (timeZone && { timeZone: timeZone }), (format && utils_1.getNamedFormat(formats, type, format, onError)));
|
|
39
|
+
var defaults = __assign(__assign({}, (timeZone && { timeZone: timeZone })), (format && utils_1.getNamedFormat(formats, type, format, onError)));
|
|
40
40
|
var filteredOptions = utils_1.filterProps(options, DATE_TIME_FORMAT_OPTIONS, defaults);
|
|
41
41
|
if (type === 'time' &&
|
|
42
42
|
!filteredOptions.hour &&
|
|
43
43
|
!filteredOptions.minute &&
|
|
44
44
|
!filteredOptions.second) {
|
|
45
45
|
// Add default formatting options if hour, minute, or second isn't defined.
|
|
46
|
-
filteredOptions = __assign({}, filteredOptions, { hour: 'numeric', minute: 'numeric' });
|
|
46
|
+
filteredOptions = __assign(__assign({}, filteredOptions), { hour: 'numeric', minute: 'numeric' });
|
|
47
47
|
}
|
|
48
48
|
return getDateTimeFormat(locale, filteredOptions);
|
|
49
49
|
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { IntlConfig, Formatters, IntlFormatters } from '../types';
|
|
2
|
+
export declare function formatDisplayName({ locale, onError }: Pick<IntlConfig, 'locale' | 'onError'>, getDisplayNames: Formatters['getDisplayNames'], value: Parameters<IntlFormatters['formatDisplayName']>[0], options?: Parameters<IntlFormatters['formatDisplayName']>[1]): string | undefined;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var utils_1 = require("../utils");
|
|
4
|
+
var DISPLAY_NAMES_OPTONS = [
|
|
5
|
+
'localeMatcher',
|
|
6
|
+
'style',
|
|
7
|
+
'type',
|
|
8
|
+
'fallback',
|
|
9
|
+
];
|
|
10
|
+
function formatDisplayName(_a, getDisplayNames, value, options) {
|
|
11
|
+
var locale = _a.locale, onError = _a.onError;
|
|
12
|
+
if (options === void 0) { options = {}; }
|
|
13
|
+
var DisplayNames = Intl.DisplayNames;
|
|
14
|
+
if (!DisplayNames) {
|
|
15
|
+
onError(utils_1.createError("Intl.DisplayNames is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-displaynames\"\n"));
|
|
16
|
+
}
|
|
17
|
+
var filteredOptions = utils_1.filterProps(options, DISPLAY_NAMES_OPTONS);
|
|
18
|
+
try {
|
|
19
|
+
return getDisplayNames(locale, filteredOptions).of(value);
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
onError(utils_1.createError('Error formatting display name.', e));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.formatDisplayName = formatDisplayName;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Formatters, IntlConfig, MessageDescriptor } from '../types';
|
|
3
3
|
import { PrimitiveType } from 'intl-messageformat';
|
|
4
|
+
export declare const prepareIntlMessageFormatHtmlOutput: (chunks: (string | object)[]) => React.ReactElement<any, string | ((props: any) => React.ReactElement<any, string | any | (new (props: any) => React.Component<any, any, any>)> | null) | (new (props: any) => React.Component<any, any, any>)>;
|
|
4
5
|
export declare function formatMessage({ locale, formats, messages, defaultLocale, defaultFormats, onError, }: Pick<IntlConfig, 'locale' | 'formats' | 'messages' | 'defaultLocale' | 'defaultFormats' | 'onError'>, state: Formatters, messageDescriptor?: MessageDescriptor, values?: Record<string, PrimitiveType>): string;
|
|
5
6
|
export declare function formatHTMLMessage(config: Pick<IntlConfig, 'locale' | 'formats' | 'messages' | 'defaultLocale' | 'defaultFormats' | 'onError'>, state: Formatters, messageDescriptor?: MessageDescriptor, rawValues?: Record<string, PrimitiveType>): React.ReactNode;
|
|
@@ -15,13 +15,16 @@ var __assign = (this && this.__assign) || function () {
|
|
|
15
15
|
};
|
|
16
16
|
return __assign.apply(this, arguments);
|
|
17
17
|
};
|
|
18
|
+
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
19
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
20
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
21
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
22
|
+
r[k] = a[j];
|
|
23
|
+
return r;
|
|
24
|
+
};
|
|
18
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
// does not export a default
|
|
22
|
-
// https://github.com/rollup/rollup/issues/1267
|
|
23
|
-
var invariant_ = require("invariant");
|
|
24
|
-
var invariant = invariant_.default || invariant_;
|
|
26
|
+
var React = require("react");
|
|
27
|
+
var intl_utils_1 = require("@formatjs/intl-utils");
|
|
25
28
|
var utils_1 = require("../utils");
|
|
26
29
|
var intl_messageformat_1 = require("intl-messageformat");
|
|
27
30
|
function setTimeZoneInOptions(opts, timeZone) {
|
|
@@ -31,9 +34,9 @@ function setTimeZoneInOptions(opts, timeZone) {
|
|
|
31
34
|
}, {});
|
|
32
35
|
}
|
|
33
36
|
function deepMergeOptions(opts1, opts2) {
|
|
34
|
-
var keys = Object.keys(__assign({}, opts1, opts2));
|
|
37
|
+
var keys = Object.keys(__assign(__assign({}, opts1), opts2));
|
|
35
38
|
return keys.reduce(function (all, k) {
|
|
36
|
-
all[k] = __assign({}, (opts1[k] || {}), (opts2[k] || {}));
|
|
39
|
+
all[k] = __assign(__assign({}, (opts1[k] || {})), (opts2[k] || {}));
|
|
37
40
|
return all;
|
|
38
41
|
}, {});
|
|
39
42
|
}
|
|
@@ -42,19 +45,17 @@ function deepMergeFormatsAndSetTimeZone(f1, timeZone) {
|
|
|
42
45
|
return f1;
|
|
43
46
|
}
|
|
44
47
|
var mfFormats = intl_messageformat_1.default.formats;
|
|
45
|
-
return __assign({}, mfFormats, f1, { date: deepMergeOptions(setTimeZoneInOptions(mfFormats.date, timeZone), setTimeZoneInOptions(f1.date || {}, timeZone)), time: deepMergeOptions(setTimeZoneInOptions(mfFormats.time, timeZone), setTimeZoneInOptions(f1.time || {}, timeZone)) });
|
|
48
|
+
return __assign(__assign(__assign({}, mfFormats), f1), { date: deepMergeOptions(setTimeZoneInOptions(mfFormats.date, timeZone), setTimeZoneInOptions(f1.date || {}, timeZone)), time: deepMergeOptions(setTimeZoneInOptions(mfFormats.time, timeZone), setTimeZoneInOptions(f1.time || {}, timeZone)) });
|
|
46
49
|
}
|
|
50
|
+
exports.prepareIntlMessageFormatHtmlOutput = function (chunks) { return React.createElement.apply(React, __spreadArrays([React.Fragment, null], chunks)); };
|
|
47
51
|
function formatMessage(_a, state, messageDescriptor, values) {
|
|
48
52
|
var locale = _a.locale, formats = _a.formats, messages = _a.messages, defaultLocale = _a.defaultLocale, defaultFormats = _a.defaultFormats, onError = _a.onError, timeZone = _a.timeZone;
|
|
49
53
|
if (messageDescriptor === void 0) { messageDescriptor = { id: '' }; }
|
|
50
54
|
if (values === void 0) { values = {}; }
|
|
51
55
|
var id = messageDescriptor.id, defaultMessage = messageDescriptor.defaultMessage;
|
|
52
56
|
// `id` is a required field of a Message Descriptor.
|
|
53
|
-
invariant(id, '[React Intl] An `id` must be provided to format a message.');
|
|
54
|
-
|
|
55
|
-
throw new Error('[React Intl] An `id` must be provided to format a message.');
|
|
56
|
-
}
|
|
57
|
-
var message = messages && messages[id];
|
|
57
|
+
intl_utils_1.invariant(!!id, '[React Intl] An `id` must be provided to format a message.');
|
|
58
|
+
var message = messages && messages[String(id)];
|
|
58
59
|
formats = deepMergeFormatsAndSetTimeZone(formats, timeZone);
|
|
59
60
|
defaultFormats = deepMergeFormatsAndSetTimeZone(defaultFormats, timeZone);
|
|
60
61
|
var formattedMessageParts = [];
|
|
@@ -93,15 +94,15 @@ function formatMessage(_a, state, messageDescriptor, values) {
|
|
|
93
94
|
onError(utils_1.createError("Cannot format message: \"" + id + "\", " +
|
|
94
95
|
("using message " + (message || defaultMessage ? 'source' : 'id') + " as fallback.")));
|
|
95
96
|
if (typeof message === 'string') {
|
|
96
|
-
return message || defaultMessage || id;
|
|
97
|
+
return message || defaultMessage || String(id);
|
|
97
98
|
}
|
|
98
|
-
return defaultMessage || id;
|
|
99
|
+
return defaultMessage || String(id);
|
|
99
100
|
}
|
|
100
101
|
if (formattedMessageParts.length === 1 &&
|
|
101
102
|
typeof formattedMessageParts[0] === 'string') {
|
|
102
|
-
return formattedMessageParts[0] || defaultMessage || id;
|
|
103
|
+
return formattedMessageParts[0] || defaultMessage || String(id);
|
|
103
104
|
}
|
|
104
|
-
return formattedMessageParts;
|
|
105
|
+
return exports.prepareIntlMessageFormatHtmlOutput(formattedMessageParts);
|
|
105
106
|
}
|
|
106
107
|
exports.formatMessage = formatMessage;
|
|
107
108
|
function formatHTMLMessage(config, state, messageDescriptor, rawValues) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
export * from './types';
|
|
3
|
-
export
|
|
3
|
+
export declare function defineMessages<T, U extends Record<string, T>>(msgs: U): U;
|
|
4
4
|
import { CustomFormatConfig } from './types';
|
|
5
5
|
import { UnifiedNumberFormatOptions } from '@formatjs/intl-unified-numberformat';
|
|
6
6
|
import { IntlListFormatOptions } from '@formatjs/intl-listformat';
|
|
7
|
+
import { DisplayNamesOptions } from '@formatjs/intl-displaynames/lib';
|
|
7
8
|
export { default as injectIntl, Provider as RawIntlProvider, Context as IntlContext, WithIntlProps, WrappedComponentProps, } from './components/injectIntl';
|
|
8
9
|
export { default as useIntl } from './components/useIntl';
|
|
9
10
|
export { default as IntlProvider, createIntl } from './components/provider';
|
|
@@ -19,11 +20,14 @@ export declare const FormattedNumber: React.FC<UnifiedNumberFormatOptions & Cust
|
|
|
19
20
|
export declare const FormattedList: React.FC<IntlListFormatOptions & {
|
|
20
21
|
value: React.ReactNode[];
|
|
21
22
|
}>;
|
|
22
|
-
export declare const
|
|
23
|
+
export declare const FormattedDisplayName: React.FC<DisplayNamesOptions & {
|
|
24
|
+
value: string | number | object;
|
|
25
|
+
}>;
|
|
26
|
+
export declare const FormattedDateParts: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
|
|
23
27
|
value: string | number | Date | undefined;
|
|
24
28
|
children(val: Intl.DateTimeFormatPart[]): React.ReactElement<any, string | ((props: any) => React.ReactElement<any, string | any | (new (props: any) => React.Component<any, any, any>)> | null) | (new (props: any) => React.Component<any, any, any>)> | null;
|
|
25
29
|
}>;
|
|
26
|
-
export declare const FormattedTimeParts: React.
|
|
30
|
+
export declare const FormattedTimeParts: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
|
|
27
31
|
value: string | number | Date | undefined;
|
|
28
32
|
children(val: Intl.DateTimeFormatPart[]): React.ReactElement<any, string | ((props: any) => React.ReactElement<any, string | any | (new (props: any) => React.Component<any, any, any>)> | null) | (new (props: any) => React.Component<any, any, any>)> | null;
|
|
29
33
|
}>;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
function defineMessages(msgs) {
|
|
4
|
+
return msgs;
|
|
5
|
+
}
|
|
6
|
+
exports.defineMessages = defineMessages;
|
|
5
7
|
var createFormattedComponent_1 = require("./components/createFormattedComponent");
|
|
6
8
|
var injectIntl_1 = require("./components/injectIntl");
|
|
7
9
|
exports.injectIntl = injectIntl_1.default;
|
|
@@ -17,6 +19,7 @@ exports.FormattedDate = createFormattedComponent_1.createFormattedComponent('for
|
|
|
17
19
|
exports.FormattedTime = createFormattedComponent_1.createFormattedComponent('formatTime');
|
|
18
20
|
exports.FormattedNumber = createFormattedComponent_1.createFormattedComponent('formatNumber');
|
|
19
21
|
exports.FormattedList = createFormattedComponent_1.createFormattedComponent('formatList');
|
|
22
|
+
exports.FormattedDisplayName = createFormattedComponent_1.createFormattedComponent('formatDisplayName');
|
|
20
23
|
exports.FormattedDateParts = createFormattedComponent_1.createFormattedDateTimePartsComponent('formatDate');
|
|
21
24
|
exports.FormattedTimeParts = createFormattedComponent_1.createFormattedDateTimePartsComponent('formatTime');
|
|
22
25
|
var createFormattedComponent_2 = require("./components/createFormattedComponent");
|
package/dist/react-intl.api.md
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
```ts
|
|
6
6
|
|
|
7
|
+
import { DisplayNames } from '@formatjs/intl-displaynames';
|
|
8
|
+
import { DisplayNamesOptions } from '@formatjs/intl-displaynames';
|
|
9
|
+
import { DisplayNamesOptions as DisplayNamesOptions_2 } from '@formatjs/intl-displaynames/lib';
|
|
7
10
|
import * as React from 'react';
|
|
8
11
|
|
|
9
12
|
// Warning: (ae-forgotten-export) The symbol "OptionalIntlConfig" needs to be exported by the entry point index.d.ts
|
|
@@ -36,6 +39,9 @@ export function defineMessages<T, U extends Record<string, T>>(msgs: U): U;
|
|
|
36
39
|
// @public (undocumented)
|
|
37
40
|
export type FormatDateOptions = Exclude<Intl.DateTimeFormatOptions, 'localeMatcher'> & CustomFormatConfig;
|
|
38
41
|
|
|
42
|
+
// @public (undocumented)
|
|
43
|
+
export type FormatDisplayNameOptions = Exclude<DisplayNamesOptions, 'localeMatcher'>;
|
|
44
|
+
|
|
39
45
|
// Warning: (ae-forgotten-export) The symbol "IntlListFormatOptions" needs to be exported by the entry point index.d.ts
|
|
40
46
|
//
|
|
41
47
|
// @public (undocumented)
|
|
@@ -58,11 +64,16 @@ export const FormattedDate: React.FC<Intl.DateTimeFormatOptions & CustomFormatCo
|
|
|
58
64
|
}>;
|
|
59
65
|
|
|
60
66
|
// @public (undocumented)
|
|
61
|
-
export const FormattedDateParts: React.
|
|
67
|
+
export const FormattedDateParts: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
|
|
62
68
|
value: string | number | Date | undefined;
|
|
63
69
|
children(val: Intl.DateTimeFormatPart[]): React.ReactElement<any, string | ((props: any) => React.ReactElement<any, string | any | (new (props: any) => React.Component<any, any, any>)> | null) | (new (props: any) => React.Component<any, any, any>)> | null;
|
|
64
70
|
}>;
|
|
65
71
|
|
|
72
|
+
// @public (undocumented)
|
|
73
|
+
export const FormattedDisplayName: React.FC<DisplayNamesOptions_2 & {
|
|
74
|
+
value: string | number | object;
|
|
75
|
+
}>;
|
|
76
|
+
|
|
66
77
|
// Warning: (ae-forgotten-export) The symbol "PrimitiveType" needs to be exported by the entry point index.d.ts
|
|
67
78
|
//
|
|
68
79
|
// @public (undocumented)
|
|
@@ -116,7 +127,7 @@ export const FormattedNumberParts: React.FC<Formatter['formatNumber'] & {
|
|
|
116
127
|
// Warning: (ae-forgotten-export) The symbol "Props" needs to be exported by the entry point index.d.ts
|
|
117
128
|
//
|
|
118
129
|
// @public (undocumented)
|
|
119
|
-
export const FormattedPlural: React.ForwardRefExoticComponent<Pick<Props_2, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "localeMatcher" | "
|
|
130
|
+
export const FormattedPlural: React.ForwardRefExoticComponent<Pick<Props_2, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "localeMatcher" | "format" | "type" | "value"> & {
|
|
120
131
|
forwardedRef?: ((instance: any) => void) | React.RefObject<any> | null | undefined;
|
|
121
132
|
} & React.RefAttributes<any>> & {
|
|
122
133
|
WrappedComponent: React.ComponentType<Props_2>;
|
|
@@ -156,7 +167,7 @@ export const FormattedTime: React.FC<Intl.DateTimeFormatOptions & CustomFormatCo
|
|
|
156
167
|
}>;
|
|
157
168
|
|
|
158
169
|
// @public (undocumented)
|
|
159
|
-
export const FormattedTimeParts: React.
|
|
170
|
+
export const FormattedTimeParts: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig & {
|
|
160
171
|
value: string | number | Date | undefined;
|
|
161
172
|
children(val: Intl.DateTimeFormatPart[]): React.ReactElement<any, string | ((props: any) => React.ReactElement<any, string | any | (new (props: any) => React.Component<any, any, any>)> | null) | (new (props: any) => React.Component<any, any, any>)> | null;
|
|
162
173
|
}>;
|
|
@@ -165,6 +176,8 @@ export const FormattedTimeParts: React.FunctionComponent<Intl.DateTimeFormatOpti
|
|
|
165
176
|
export interface Formatters {
|
|
166
177
|
// (undocumented)
|
|
167
178
|
getDateTimeFormat(...args: ConstructorParameters<typeof Intl.DateTimeFormat>): Intl.DateTimeFormat;
|
|
179
|
+
// (undocumented)
|
|
180
|
+
getDisplayNames(...args: ConstructorParameters<typeof DisplayNames>): DisplayNames;
|
|
168
181
|
// Warning: (ae-forgotten-export) The symbol "ListFormat" needs to be exported by the entry point index.d.ts
|
|
169
182
|
//
|
|
170
183
|
// (undocumented)
|
|
@@ -200,6 +213,8 @@ export interface IntlCache {
|
|
|
200
213
|
// (undocumented)
|
|
201
214
|
dateTime: Record<string, Intl.DateTimeFormat>;
|
|
202
215
|
// (undocumented)
|
|
216
|
+
displayNames: Record<string, DisplayNames>;
|
|
217
|
+
// (undocumented)
|
|
203
218
|
list: Record<string, ListFormat>;
|
|
204
219
|
// (undocumented)
|
|
205
220
|
message: Record<string, IntlMessageFormat>;
|
|
@@ -243,6 +258,8 @@ export interface IntlFormatters {
|
|
|
243
258
|
// (undocumented)
|
|
244
259
|
formatDateToParts(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): Intl.DateTimeFormatPart[];
|
|
245
260
|
// (undocumented)
|
|
261
|
+
formatDisplayName(value: Parameters<DisplayNames['of']>[0], opts?: FormatDisplayNameOptions): string | undefined;
|
|
262
|
+
// (undocumented)
|
|
246
263
|
formatHTMLMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType>): React.ReactNode;
|
|
247
264
|
// (undocumented)
|
|
248
265
|
formatList(values: Array<string>, opts?: FormatListOptions): string;
|
|
@@ -295,14 +312,14 @@ export interface MessageDescriptor {
|
|
|
295
312
|
// (undocumented)
|
|
296
313
|
description?: string | object;
|
|
297
314
|
// (undocumented)
|
|
298
|
-
id?: string;
|
|
315
|
+
id?: string | number;
|
|
299
316
|
}
|
|
300
317
|
|
|
301
318
|
// @public (undocumented)
|
|
302
319
|
export type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
|
|
303
320
|
|
|
304
321
|
// @public (undocumented)
|
|
305
|
-
export const RawIntlProvider: React.
|
|
322
|
+
export const RawIntlProvider: React.Provider<IntlShape>;
|
|
306
323
|
|
|
307
324
|
// @public (undocumented)
|
|
308
325
|
export function useIntl(): IntlShape;
|