react-intl 4.2.0 → 4.3.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 +28 -0
- package/dist/components/message.d.ts +1 -1
- package/dist/error.d.ts +4 -2
- package/dist/error.js +10 -1
- package/dist/formatters/displayName.js +1 -1
- package/dist/formatters/list.js +1 -1
- package/dist/formatters/message.js +4 -4
- package/dist/formatters/plural.js +1 -1
- package/dist/formatters/relativeTime.js +1 -1
- package/dist/index.js +1 -0
- package/dist/react-intl.api.md +12 -9
- package/dist/react-intl.d.ts +99 -16
- package/dist/react-intl.js +62 -20
- 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 +2 -2
- package/lib/components/message.d.ts +1 -1
- package/lib/error.d.ts +4 -2
- package/lib/error.js +10 -1
- package/lib/formatters/displayName.js +1 -1
- package/lib/formatters/list.js +1 -1
- package/lib/formatters/message.js +4 -4
- package/lib/formatters/plural.js +1 -1
- package/lib/formatters/relativeTime.js +1 -1
- package/lib/index.js +1 -1
- package/lib/react-intl.d.ts +6 -5
- package/lib/tsdoc-metadata.json +1 -1
- package/lib/types.d.ts +2 -2
- package/package.json +13 -13
- package/src/components/message.tsx +4 -3
- package/src/error.ts +6 -2
- package/src/formatters/message.ts +15 -18
- package/src/types.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,34 @@
|
|
|
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
|
+
### [4.3.1](https://github.com/formatjs/react-intl/compare/v4.3.0...v4.3.1) (2020-03-28)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* tweak FormatXMLElementFn ([a914dc0](https://github.com/formatjs/react-intl/commit/a914dc059cc8d0c04baec6a63513cb686ff6dad3))
|
|
11
|
+
|
|
12
|
+
## [4.3.0](https://github.com/formatjs/react-intl/compare/v4.2.2...v4.3.0) (2020-03-26)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* **react-intl:** store original message descriptor in the error ([22531bd](https://github.com/formatjs/react-intl/commit/22531bde78e0f3846b583b5bf0e4115e872f9a54))
|
|
18
|
+
|
|
19
|
+
### [4.2.2](https://github.com/formatjs/react-intl/compare/v4.2.1...v4.2.2) (2020-03-21)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
* turn on preserveConstEnums so we export ReactIntlErrorCode ([8e00610](https://github.com/formatjs/react-intl/commit/8e006105a7286aba0efdb985eb588d03597b186b))
|
|
25
|
+
|
|
26
|
+
### [4.2.1](https://github.com/formatjs/react-intl/compare/v4.2.0...v4.2.1) (2020-03-21)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Bug Fixes
|
|
30
|
+
|
|
31
|
+
* include intl-displaynames types in bundled react-intl.d.ts ([77ef36c](https://github.com/formatjs/react-intl/commit/77ef36cb2f522587c454469241d9a4974963ccb8))
|
|
32
|
+
|
|
5
33
|
## [4.2.0](https://github.com/formatjs/react-intl/compare/v4.1.1...v4.2.0) (2020-03-21)
|
|
6
34
|
|
|
7
35
|
|
|
@@ -6,7 +6,7 @@ export interface Props<V extends Record<string, any> = Record<string, React.Reac
|
|
|
6
6
|
tagName?: React.ElementType<any>;
|
|
7
7
|
children?(...nodes: React.ReactNodeArray): React.ReactNode;
|
|
8
8
|
}
|
|
9
|
-
declare class FormattedMessage<
|
|
9
|
+
declare class FormattedMessage<V extends Record<string, any> = Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<React.ReactNode, React.ReactNode>>> extends React.Component<Props<V>> {
|
|
10
10
|
static displayName: string;
|
|
11
11
|
static defaultProps: {
|
|
12
12
|
values: {};
|
package/dist/error.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MessageDescriptor } from "./types";
|
|
1
2
|
export declare const enum ReactIntlErrorCode {
|
|
2
3
|
FORMAT_ERROR = "FORMAT_ERROR",
|
|
3
4
|
UNSUPPORTED_FORMATTER = "UNSUPPORTED_FORMATTER",
|
|
@@ -6,6 +7,7 @@ export declare const enum ReactIntlErrorCode {
|
|
|
6
7
|
MISSING_TRANSLATION = "MISSING_TRANSLATION"
|
|
7
8
|
}
|
|
8
9
|
export declare class ReactIntlError extends Error {
|
|
9
|
-
code: ReactIntlErrorCode;
|
|
10
|
-
|
|
10
|
+
readonly code: ReactIntlErrorCode;
|
|
11
|
+
readonly descriptor?: MessageDescriptor;
|
|
12
|
+
constructor(code: ReactIntlErrorCode, message: string, descriptor?: MessageDescriptor, exception?: Error);
|
|
11
13
|
}
|
package/dist/error.js
CHANGED
|
@@ -13,11 +13,20 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
13
13
|
};
|
|
14
14
|
})();
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
var ReactIntlErrorCode;
|
|
17
|
+
(function (ReactIntlErrorCode) {
|
|
18
|
+
ReactIntlErrorCode["FORMAT_ERROR"] = "FORMAT_ERROR";
|
|
19
|
+
ReactIntlErrorCode["UNSUPPORTED_FORMATTER"] = "UNSUPPORTED_FORMATTER";
|
|
20
|
+
ReactIntlErrorCode["INVALID_CONFIG"] = "INVALID_CONFIG";
|
|
21
|
+
ReactIntlErrorCode["MISSING_DATA"] = "MISSING_DATA";
|
|
22
|
+
ReactIntlErrorCode["MISSING_TRANSLATION"] = "MISSING_TRANSLATION";
|
|
23
|
+
})(ReactIntlErrorCode = exports.ReactIntlErrorCode || (exports.ReactIntlErrorCode = {}));
|
|
16
24
|
var ReactIntlError = /** @class */ (function (_super) {
|
|
17
25
|
__extends(ReactIntlError, _super);
|
|
18
|
-
function ReactIntlError(code, message, exception) {
|
|
26
|
+
function ReactIntlError(code, message, descriptor, exception) {
|
|
19
27
|
var _this = _super.call(this, "[React Intl Error " + code + "] " + message + " " + (exception ? "\n" + exception.stack : '')) || this;
|
|
20
28
|
_this.code = code;
|
|
29
|
+
_this.descriptor = descriptor;
|
|
21
30
|
if (typeof Error.captureStackTrace === 'function') {
|
|
22
31
|
Error.captureStackTrace(_this, ReactIntlError);
|
|
23
32
|
}
|
|
@@ -14,7 +14,7 @@ function formatDisplayName(_a, getDisplayNames, value, options) {
|
|
|
14
14
|
if (options === void 0) { options = {}; }
|
|
15
15
|
var DisplayNames = Intl.DisplayNames;
|
|
16
16
|
if (!DisplayNames) {
|
|
17
|
-
onError(new intl_messageformat_1.FormatError("Intl.DisplayNames is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-displaynames\"\n",
|
|
17
|
+
onError(new intl_messageformat_1.FormatError("Intl.DisplayNames is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-displaynames\"\n", "MISSING_INTL_API" /* MISSING_INTL_API */));
|
|
18
18
|
}
|
|
19
19
|
var filteredOptions = utils_1.filterProps(options, DISPLAY_NAMES_OPTONS);
|
|
20
20
|
try {
|
package/dist/formatters/list.js
CHANGED
|
@@ -17,7 +17,7 @@ function formatList(_a, getListFormat, values, options) {
|
|
|
17
17
|
if (options === void 0) { options = {}; }
|
|
18
18
|
var ListFormat = Intl.ListFormat;
|
|
19
19
|
if (!ListFormat) {
|
|
20
|
-
onError(new intl_messageformat_1.FormatError("Intl.ListFormat is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-listformat\"\n",
|
|
20
|
+
onError(new intl_messageformat_1.FormatError("Intl.ListFormat is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-listformat\"\n", "MISSING_INTL_API" /* MISSING_INTL_API */));
|
|
21
21
|
}
|
|
22
22
|
var filteredOptions = utils_1.filterProps(options, LIST_FORMAT_OPTIONS);
|
|
23
23
|
try {
|
|
@@ -70,7 +70,7 @@ function formatMessage(_a, state, messageDescriptor, values) {
|
|
|
70
70
|
}
|
|
71
71
|
catch (e) {
|
|
72
72
|
onError(new error_1.ReactIntlError("FORMAT_ERROR" /* FORMAT_ERROR */, "Error formatting message: \"" + id + "\" for locale: \"" + locale + "\"" +
|
|
73
|
-
(defaultMessage ? ', using default message as fallback.' : ''), e));
|
|
73
|
+
(defaultMessage ? ', using default message as fallback.' : ''), messageDescriptor, e));
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
else if (!defaultMessage ||
|
|
@@ -79,7 +79,7 @@ function formatMessage(_a, state, messageDescriptor, values) {
|
|
|
79
79
|
// when no `messages` are passed into the <IntlProvider> for the
|
|
80
80
|
// default locale.
|
|
81
81
|
onError(new error_1.ReactIntlError("MISSING_TRANSLATION" /* MISSING_TRANSLATION */, "Missing message: \"" + id + "\" for locale: \"" + locale + "\"" +
|
|
82
|
-
(defaultMessage ? ', using default message as fallback.' : '')));
|
|
82
|
+
(defaultMessage ? ', using default message as fallback.' : ''), messageDescriptor));
|
|
83
83
|
}
|
|
84
84
|
if (!formattedMessageParts && defaultMessage) {
|
|
85
85
|
try {
|
|
@@ -87,12 +87,12 @@ function formatMessage(_a, state, messageDescriptor, values) {
|
|
|
87
87
|
formattedMessageParts = formatter.format(values);
|
|
88
88
|
}
|
|
89
89
|
catch (e) {
|
|
90
|
-
onError(new error_1.ReactIntlError("FORMAT_ERROR" /* FORMAT_ERROR */, "Error formatting the default message for: \"" + id + "\"", e));
|
|
90
|
+
onError(new error_1.ReactIntlError("FORMAT_ERROR" /* FORMAT_ERROR */, "Error formatting the default message for: \"" + id + "\"", messageDescriptor, e));
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
if (!formattedMessageParts) {
|
|
94
94
|
onError(new error_1.ReactIntlError("FORMAT_ERROR" /* FORMAT_ERROR */, "Cannot format message: \"" + id + "\", " +
|
|
95
|
-
("using message " + (message || defaultMessage ? 'source' : 'id') + " as fallback.")));
|
|
95
|
+
("using message " + (message || defaultMessage ? 'source' : 'id') + " as fallback."), messageDescriptor));
|
|
96
96
|
if (typeof message === 'string') {
|
|
97
97
|
return message || defaultMessage || String(id);
|
|
98
98
|
}
|
|
@@ -11,7 +11,7 @@ function formatPlural(_a, getPluralRules, value, options) {
|
|
|
11
11
|
var locale = _a.locale, onError = _a.onError;
|
|
12
12
|
if (options === void 0) { options = {}; }
|
|
13
13
|
if (!Intl.PluralRules) {
|
|
14
|
-
onError(new intl_messageformat_1.FormatError("Intl.PluralRules is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-pluralrules\"\n",
|
|
14
|
+
onError(new intl_messageformat_1.FormatError("Intl.PluralRules is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-pluralrules\"\n", "MISSING_INTL_API" /* MISSING_INTL_API */));
|
|
15
15
|
}
|
|
16
16
|
var filteredOptions = utils_1.filterProps(options, PLURAL_FORMAT_OPTIONS);
|
|
17
17
|
try {
|
|
@@ -22,7 +22,7 @@ function formatRelativeTime(config, getRelativeTimeFormat, value, unit, options)
|
|
|
22
22
|
}
|
|
23
23
|
var RelativeTimeFormat = Intl.RelativeTimeFormat;
|
|
24
24
|
if (!RelativeTimeFormat) {
|
|
25
|
-
config.onError(new intl_messageformat_1.FormatError("Intl.RelativeTimeFormat is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-relativetimeformat\"\n",
|
|
25
|
+
config.onError(new intl_messageformat_1.FormatError("Intl.RelativeTimeFormat is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-relativetimeformat\"\n", "MISSING_INTL_API" /* MISSING_INTL_API */));
|
|
26
26
|
}
|
|
27
27
|
try {
|
|
28
28
|
return getFormatter(config, getRelativeTimeFormat, options).format(value, unit);
|
package/dist/index.js
CHANGED
package/dist/react-intl.api.md
CHANGED
|
@@ -4,9 +4,6 @@
|
|
|
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';
|
|
10
7
|
import * as React from 'react';
|
|
11
8
|
|
|
12
9
|
// Warning: (ae-forgotten-export) The symbol "OptionalIntlConfig" needs to be exported by the entry point index.d.ts
|
|
@@ -39,6 +36,8 @@ export function defineMessages<T, U extends Record<string, T>>(msgs: U): U;
|
|
|
39
36
|
// @public (undocumented)
|
|
40
37
|
export type FormatDateOptions = Exclude<Intl.DateTimeFormatOptions, 'localeMatcher'> & CustomFormatConfig;
|
|
41
38
|
|
|
39
|
+
// Warning: (ae-forgotten-export) The symbol "DisplayNamesOptions" needs to be exported by the entry point index.d.ts
|
|
40
|
+
//
|
|
42
41
|
// @public (undocumented)
|
|
43
42
|
export type FormatDisplayNameOptions = Exclude<DisplayNamesOptions, 'localeMatcher'>;
|
|
44
43
|
|
|
@@ -70,7 +69,7 @@ export const FormattedDateParts: React.FC<Intl.DateTimeFormatOptions & CustomFor
|
|
|
70
69
|
}>;
|
|
71
70
|
|
|
72
71
|
// @public (undocumented)
|
|
73
|
-
export const FormattedDisplayName: React.FC<
|
|
72
|
+
export const FormattedDisplayName: React.FC<DisplayNamesOptions & {
|
|
74
73
|
value: string | number | object;
|
|
75
74
|
}>;
|
|
76
75
|
|
|
@@ -84,7 +83,7 @@ export const FormattedList: React.FC<IntlListFormatOptions & {
|
|
|
84
83
|
// Warning: (ae-forgotten-export) The symbol "Props" needs to be exported by the entry point index.d.ts
|
|
85
84
|
//
|
|
86
85
|
// @public (undocumented)
|
|
87
|
-
export class FormattedMessage<
|
|
86
|
+
export class FormattedMessage<V extends Record<string, any> = Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<React.ReactNode, React.ReactNode>>> extends React.Component<Props_3<V>> {
|
|
88
87
|
// (undocumented)
|
|
89
88
|
static defaultProps: {
|
|
90
89
|
values: {};
|
|
@@ -162,6 +161,8 @@ export const FormattedTimeParts: React.FC<Intl.DateTimeFormatOptions & CustomFor
|
|
|
162
161
|
export interface Formatters {
|
|
163
162
|
// (undocumented)
|
|
164
163
|
getDateTimeFormat(...args: ConstructorParameters<typeof Intl.DateTimeFormat>): Intl.DateTimeFormat;
|
|
164
|
+
// Warning: (ae-forgotten-export) The symbol "DisplayNames" needs to be exported by the entry point index.d.ts
|
|
165
|
+
//
|
|
165
166
|
// (undocumented)
|
|
166
167
|
getDisplayNames(...args: ConstructorParameters<typeof DisplayNames>): DisplayNames;
|
|
167
168
|
// Warning: (ae-forgotten-export) The symbol "ListFormat" needs to be exported by the entry point index.d.ts
|
|
@@ -242,7 +243,7 @@ export interface IntlConfig {
|
|
|
242
243
|
export const IntlContext: React.Context<IntlShape>;
|
|
243
244
|
|
|
244
245
|
// @public (undocumented)
|
|
245
|
-
export interface IntlFormatters<T = React.ReactNode> {
|
|
246
|
+
export interface IntlFormatters<T = React.ReactNode, R = T> {
|
|
246
247
|
// (undocumented)
|
|
247
248
|
formatDate(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
|
|
248
249
|
// (undocumented)
|
|
@@ -256,7 +257,7 @@ export interface IntlFormatters<T = React.ReactNode> {
|
|
|
256
257
|
// (undocumented)
|
|
257
258
|
formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType>): string;
|
|
258
259
|
// (undocumented)
|
|
259
|
-
formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<T>>): string | React.ReactNodeArray;
|
|
260
|
+
formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<T, R>>): string | React.ReactNodeArray;
|
|
260
261
|
// (undocumented)
|
|
261
262
|
formatNumber(value: Parameters<Intl.NumberFormat['format']>[0], opts?: FormatNumberOptions): string;
|
|
262
263
|
// (undocumented)
|
|
@@ -311,9 +312,11 @@ export const RawIntlProvider: React.Provider<IntlShape>;
|
|
|
311
312
|
|
|
312
313
|
// @public (undocumented)
|
|
313
314
|
export class ReactIntlError extends Error {
|
|
314
|
-
constructor(code: ReactIntlErrorCode, message: string, exception?: Error);
|
|
315
|
+
constructor(code: ReactIntlErrorCode, message: string, descriptor?: MessageDescriptor, exception?: Error);
|
|
316
|
+
// (undocumented)
|
|
317
|
+
readonly code: ReactIntlErrorCode;
|
|
315
318
|
// (undocumented)
|
|
316
|
-
|
|
319
|
+
readonly descriptor?: MessageDescriptor;
|
|
317
320
|
}
|
|
318
321
|
|
|
319
322
|
// @public (undocumented)
|
package/dist/react-intl.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { DisplayNames } from '@formatjs/intl-displaynames';
|
|
2
|
-
import { DisplayNamesOptions } from '@formatjs/intl-displaynames';
|
|
3
|
-
import { DisplayNamesOptions as DisplayNamesOptions_2 } from '@formatjs/intl-displaynames/lib';
|
|
4
1
|
import * as React from 'react';
|
|
5
2
|
|
|
6
3
|
declare type ArgumentElement = BaseElement<TYPE.argument>;
|
|
@@ -20,6 +17,8 @@ export declare function createIntl(config: OptionalIntlConfig, cache?: IntlCache
|
|
|
20
17
|
|
|
21
18
|
export declare function createIntlCache(): IntlCache;
|
|
22
19
|
|
|
20
|
+
declare type CurrencyCode = string;
|
|
21
|
+
|
|
23
22
|
export declare interface CustomFormatConfig {
|
|
24
23
|
format?: string;
|
|
25
24
|
}
|
|
@@ -40,15 +39,84 @@ declare const DEFAULT_INTL_CONFIG: Pick<IntlConfig, 'formats' | 'messages' | 'ti
|
|
|
40
39
|
|
|
41
40
|
export declare function defineMessages<T, U extends Record<string, T>>(msgs: U): U;
|
|
42
41
|
|
|
42
|
+
declare class DisplayNames {
|
|
43
|
+
constructor(locales?: string | string[], options?: DisplayNamesOptions);
|
|
44
|
+
static supportedLocalesOf(locales?: string | string[], options?: Pick<DisplayNamesOptions, 'localeMatcher'>): string[];
|
|
45
|
+
static __addLocaleData(...data: DisplayNamesLocaleData[]): void;
|
|
46
|
+
of(code: string | number | object): string | undefined;
|
|
47
|
+
resolvedOptions(): DisplayNamesResolvedOptions;
|
|
48
|
+
static localeData: Record<string, DisplayNamesData>;
|
|
49
|
+
private static availableLocales;
|
|
50
|
+
private static __defaultLocale;
|
|
51
|
+
private static getDefaultLocale;
|
|
52
|
+
static readonly polyfilled = true;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
declare interface DisplayNamesData {
|
|
56
|
+
/**
|
|
57
|
+
* Note that for style fields, `short` and `narrow` might not exist.
|
|
58
|
+
* At runtime, the fallback order will be narrow -> short -> long.
|
|
59
|
+
*/
|
|
60
|
+
types: {
|
|
61
|
+
/**
|
|
62
|
+
* Maps language subtag like `zh-CN` to their display names.
|
|
63
|
+
*/
|
|
64
|
+
language: {
|
|
65
|
+
narrow: Record<LanguageTag, string>;
|
|
66
|
+
short: Record<LanguageTag, string>;
|
|
67
|
+
long: Record<LanguageTag, string>;
|
|
68
|
+
};
|
|
69
|
+
region: {
|
|
70
|
+
narrow: Record<RegionCode, string>;
|
|
71
|
+
short: Record<RegionCode, string>;
|
|
72
|
+
long: Record<RegionCode, string>;
|
|
73
|
+
};
|
|
74
|
+
script: {
|
|
75
|
+
narrow: Record<ScriptCode, string>;
|
|
76
|
+
short: Record<ScriptCode, string>;
|
|
77
|
+
long: Record<ScriptCode, string>;
|
|
78
|
+
};
|
|
79
|
+
currency: {
|
|
80
|
+
narrow: Record<CurrencyCode, string>;
|
|
81
|
+
short: Record<CurrencyCode, string>;
|
|
82
|
+
long: Record<CurrencyCode, string>;
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Not in spec, but we need this to display both language and region in display name.
|
|
87
|
+
* e.g. zh-Hans-SG + "{0}({1})" -> 简体中文(新加坡)
|
|
88
|
+
* Here {0} is replaced by language display name and {1} is replaced by region display name.
|
|
89
|
+
*/
|
|
90
|
+
patterns: {
|
|
91
|
+
locale: string;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
declare type DisplayNamesLocaleData = LocaleData<DisplayNamesData>;
|
|
96
|
+
|
|
97
|
+
declare interface DisplayNamesOptions {
|
|
98
|
+
localeMatcher?: 'lookup' | 'best fit';
|
|
99
|
+
style?: 'narrow' | 'short' | 'long';
|
|
100
|
+
type?: 'language' | 'region' | 'script' | 'currency';
|
|
101
|
+
fallback?: 'code' | 'none';
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
declare interface DisplayNamesResolvedOptions {
|
|
105
|
+
locale: string;
|
|
106
|
+
style: NonNullable<DisplayNamesOptions['style']>;
|
|
107
|
+
type: NonNullable<DisplayNamesOptions['type']>;
|
|
108
|
+
fallback: NonNullable<DisplayNamesOptions['fallback']>;
|
|
109
|
+
}
|
|
110
|
+
|
|
43
111
|
declare interface ElementPart {
|
|
44
112
|
type: 'element';
|
|
45
113
|
value: string;
|
|
46
114
|
}
|
|
47
115
|
|
|
48
116
|
declare const enum ErrorCode {
|
|
49
|
-
MISSING_VALUE =
|
|
50
|
-
INVALID_VALUE =
|
|
51
|
-
MISSING_INTL_API =
|
|
117
|
+
MISSING_VALUE = "MISSING_VALUE",
|
|
118
|
+
INVALID_VALUE = "INVALID_VALUE",
|
|
119
|
+
MISSING_INTL_API = "MISSING_INTL_API"
|
|
52
120
|
}
|
|
53
121
|
|
|
54
122
|
declare interface FieldData {
|
|
@@ -69,7 +137,15 @@ export declare type FormatDisplayNameOptions = Exclude<DisplayNamesOptions, 'loc
|
|
|
69
137
|
|
|
70
138
|
declare class FormatError extends Error {
|
|
71
139
|
readonly code: ErrorCode;
|
|
72
|
-
|
|
140
|
+
/**
|
|
141
|
+
* Original message we're trying to format
|
|
142
|
+
* `undefined` if we're only dealing w/ AST
|
|
143
|
+
*
|
|
144
|
+
* @type {(string | undefined)}
|
|
145
|
+
* @memberof FormatError
|
|
146
|
+
*/
|
|
147
|
+
readonly originalMessage: string | undefined;
|
|
148
|
+
constructor(msg: string, code: ErrorCode, originalMessage?: string);
|
|
73
149
|
toString(): string;
|
|
74
150
|
}
|
|
75
151
|
|
|
@@ -98,7 +174,7 @@ export declare const FormattedDateParts: React.FC<Intl.DateTimeFormatOptions & C
|
|
|
98
174
|
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;
|
|
99
175
|
}>;
|
|
100
176
|
|
|
101
|
-
export declare const FormattedDisplayName: React.FC<
|
|
177
|
+
export declare const FormattedDisplayName: React.FC<DisplayNamesOptions & {
|
|
102
178
|
value: string | number | object;
|
|
103
179
|
}>;
|
|
104
180
|
|
|
@@ -106,7 +182,7 @@ export declare const FormattedList: React.FC<IntlListFormatOptions & {
|
|
|
106
182
|
value: React.ReactNode[];
|
|
107
183
|
}>;
|
|
108
184
|
|
|
109
|
-
export declare class FormattedMessage<
|
|
185
|
+
export declare class FormattedMessage<V extends Record<string, any> = Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<React.ReactNode, React.ReactNode>>> extends React.Component<Props_3<V>> {
|
|
110
186
|
static displayName: string;
|
|
111
187
|
static defaultProps: {
|
|
112
188
|
values: {};
|
|
@@ -177,7 +253,7 @@ declare interface Formatters_2 {
|
|
|
177
253
|
getPluralRules(...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;
|
|
178
254
|
}
|
|
179
255
|
|
|
180
|
-
declare type FormatXMLElementFn<T
|
|
256
|
+
declare type FormatXMLElementFn<T, R = string | Array<string | T>> = (...args: Array<string | T>) => R;
|
|
181
257
|
|
|
182
258
|
export declare function injectIntl<IntlPropName extends string, P extends WrappedComponentProps<IntlPropName> = WrappedComponentProps<any>>(WrappedComponent: React.ComponentType<P>, options?: Opts<IntlPropName, false>): React.FC<WithIntlProps<P>> & {
|
|
183
259
|
WrappedComponent: React.ComponentType<P>;
|
|
@@ -211,7 +287,7 @@ export declare interface IntlConfig {
|
|
|
211
287
|
|
|
212
288
|
export declare const IntlContext: React.Context<IntlShape>;
|
|
213
289
|
|
|
214
|
-
export declare interface IntlFormatters<T = React.ReactNode> {
|
|
290
|
+
export declare interface IntlFormatters<T = React.ReactNode, R = T> {
|
|
215
291
|
formatDate(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
|
|
216
292
|
formatTime(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
|
|
217
293
|
formatDateToParts(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): Intl.DateTimeFormatPart[];
|
|
@@ -221,7 +297,7 @@ export declare interface IntlFormatters<T = React.ReactNode> {
|
|
|
221
297
|
formatNumberToParts(value: Parameters<Intl.NumberFormat['format']>[0], opts?: FormatNumberOptions): Intl.NumberFormatPart[];
|
|
222
298
|
formatPlural(value: Parameters<Intl.PluralRules['select']>[0], opts?: FormatPluralOptions): ReturnType<Intl.PluralRules['select']>;
|
|
223
299
|
formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType>): string;
|
|
224
|
-
formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<T>>): string | React.ReactNodeArray;
|
|
300
|
+
formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<T, R>>): string | React.ReactNodeArray;
|
|
225
301
|
formatList(values: Array<string>, opts?: FormatListOptions): string;
|
|
226
302
|
formatList(values: Array<string | React.ReactNode>, opts?: FormatListOptions): React.ReactNode;
|
|
227
303
|
formatDisplayName(value: Parameters<DisplayNames['of']>[0], opts?: FormatDisplayNameOptions): string | undefined;
|
|
@@ -261,8 +337,8 @@ declare class IntlMessageFormat {
|
|
|
261
337
|
private readonly message;
|
|
262
338
|
private readonly formatterCache;
|
|
263
339
|
constructor(message: string | MessageFormatElement[], locales?: string | string[], overrideFormats?: Partial<Formats>, opts?: Options);
|
|
264
|
-
format: <T = void>(values?: Record<string, string | number | boolean | Date | T | FormatXMLElementFn<T> | null | undefined> | undefined) => string | T | (string | T)[];
|
|
265
|
-
formatToParts: <T>(values?: Record<string, string | number | boolean | Date | T | FormatXMLElementFn<T> | null | undefined> | undefined) => MessageFormatPart<T>[];
|
|
340
|
+
format: <T = void>(values?: Record<string, string | number | boolean | Date | T | FormatXMLElementFn<T, string | (string | T)[]> | null | undefined> | undefined) => string | T | (string | T)[];
|
|
341
|
+
formatToParts: <T>(values?: Record<string, string | number | boolean | Date | T | FormatXMLElementFn<T, string | (string | T)[]> | null | undefined> | undefined) => MessageFormatPart<T>[];
|
|
266
342
|
resolvedOptions: () => {
|
|
267
343
|
locale: string;
|
|
268
344
|
};
|
|
@@ -373,6 +449,8 @@ declare interface IParseOptions {
|
|
|
373
449
|
[key: string]: any;
|
|
374
450
|
}
|
|
375
451
|
|
|
452
|
+
declare type LanguageTag = string;
|
|
453
|
+
|
|
376
454
|
declare type LDMLPluralRule = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other';
|
|
377
455
|
|
|
378
456
|
declare class ListFormat {
|
|
@@ -573,8 +651,9 @@ declare interface Props_3<V extends Record<string, any> = Record<string, React.R
|
|
|
573
651
|
export declare const RawIntlProvider: React.Provider<IntlShape>;
|
|
574
652
|
|
|
575
653
|
export declare class ReactIntlError extends Error {
|
|
576
|
-
code: ReactIntlErrorCode;
|
|
577
|
-
|
|
654
|
+
readonly code: ReactIntlErrorCode;
|
|
655
|
+
readonly descriptor?: MessageDescriptor;
|
|
656
|
+
constructor(code: ReactIntlErrorCode, message: string, descriptor?: MessageDescriptor, exception?: Error);
|
|
578
657
|
}
|
|
579
658
|
|
|
580
659
|
export declare const enum ReactIntlErrorCode {
|
|
@@ -585,6 +664,8 @@ export declare const enum ReactIntlErrorCode {
|
|
|
585
664
|
MISSING_TRANSLATION = "MISSING_TRANSLATION"
|
|
586
665
|
}
|
|
587
666
|
|
|
667
|
+
declare type RegionCode = string;
|
|
668
|
+
|
|
588
669
|
declare type RelativeTimeData = {
|
|
589
670
|
[u in LDMLPluralRule]?: string;
|
|
590
671
|
};
|
|
@@ -656,6 +737,8 @@ declare interface ResolvedIntlRelativeTimeFormatOptions extends Pick<IntlRelativ
|
|
|
656
737
|
numberingSystem: string;
|
|
657
738
|
}
|
|
658
739
|
|
|
740
|
+
declare type ScriptCode = string;
|
|
741
|
+
|
|
659
742
|
declare interface SelectElement extends BaseElement<TYPE.select> {
|
|
660
743
|
options: Record<string, PluralOrSelectOption>;
|
|
661
744
|
}
|