react-intl 3.12.0 → 4.1.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 +47 -0
- package/dist/components/message.d.ts +1 -1
- package/dist/components/message.js +2 -2
- package/dist/components/plural.d.ts +1 -1
- package/dist/components/provider.js +13 -8
- package/dist/error.d.ts +11 -0
- package/dist/error.js +28 -0
- package/dist/formatters/dateTime.js +5 -4
- package/dist/formatters/displayName.js +4 -2
- package/dist/formatters/list.js +4 -2
- package/dist/formatters/message.d.ts +1 -2
- package/dist/formatters/message.js +17 -34
- package/dist/formatters/number.js +3 -2
- package/dist/formatters/plural.js +4 -2
- package/dist/formatters/relativeTime.js +4 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -4
- package/dist/react-intl.api.md +29 -22
- package/dist/react-intl.d.ts +77 -36
- package/dist/react-intl.js +6267 -5860
- 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 +5 -5
- package/dist/utils.d.ts +3 -4
- package/dist/utils.js +2 -18
- package/lib/components/message.d.ts +1 -1
- package/lib/components/message.js +2 -2
- package/lib/components/plural.d.ts +1 -1
- package/lib/components/provider.js +15 -10
- package/lib/error.d.ts +11 -0
- package/lib/error.js +9 -0
- package/lib/formatters/dateTime.js +6 -5
- package/lib/formatters/displayName.js +6 -4
- package/lib/formatters/list.js +6 -4
- package/lib/formatters/message.d.ts +1 -2
- package/lib/formatters/message.js +17 -31
- package/lib/formatters/number.js +4 -3
- package/lib/formatters/plural.js +6 -4
- package/lib/formatters/relativeTime.js +6 -4
- package/lib/index.d.ts +2 -2
- package/lib/index.js +4 -2
- package/lib/react-intl.d.ts +21 -17
- package/lib/tsdoc-metadata.json +1 -1
- package/lib/types.d.ts +5 -5
- package/lib/utils.d.ts +3 -4
- package/lib/utils.js +2 -16
- package/package.json +45 -47
- package/src/components/message.tsx +6 -5
- package/src/components/provider.tsx +25 -14
- package/src/error.ts +18 -0
- package/src/formatters/dateTime.ts +30 -5
- package/src/formatters/displayName.ts +15 -4
- package/src/formatters/list.ts +15 -4
- package/src/formatters/message.ts +49 -66
- package/src/formatters/number.ts +16 -3
- package/src/formatters/plural.ts +15 -4
- package/src/formatters/relativeTime.ts +15 -4
- package/src/index.ts +4 -2
- package/src/types.ts +5 -7
- package/src/utils.ts +4 -25
- package/dist/components/html-message.d.ts +0 -11
- package/dist/components/html-message.js +0 -75
- package/lib/components/html-message.d.ts +0 -11
- package/lib/components/html-message.js +0 -43
- package/src/components/html-message.tsx +0 -68
package/dist/react-intl.d.ts
CHANGED
|
@@ -5,11 +5,6 @@ import * as React from 'react';
|
|
|
5
5
|
|
|
6
6
|
declare type ArgumentElement = BaseElement<TYPE.argument>;
|
|
7
7
|
|
|
8
|
-
declare interface ArgumentPart {
|
|
9
|
-
type: PART_TYPE.argument;
|
|
10
|
-
value: any;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
8
|
declare interface BaseElement<T extends TYPE> {
|
|
14
9
|
type: T;
|
|
15
10
|
value: string;
|
|
@@ -50,6 +45,12 @@ declare interface ElementPart {
|
|
|
50
45
|
value: string;
|
|
51
46
|
}
|
|
52
47
|
|
|
48
|
+
declare const enum ErrorCode {
|
|
49
|
+
MISSING_VALUE = 0,
|
|
50
|
+
INVALID_VALUE = 1,
|
|
51
|
+
MISSING_INTL_API = 2
|
|
52
|
+
}
|
|
53
|
+
|
|
53
54
|
declare interface FieldData {
|
|
54
55
|
'0'?: string;
|
|
55
56
|
'1'?: string;
|
|
@@ -66,6 +67,12 @@ export declare type FormatDateOptions = Exclude<Intl.DateTimeFormatOptions, 'loc
|
|
|
66
67
|
|
|
67
68
|
export declare type FormatDisplayNameOptions = Exclude<DisplayNamesOptions, 'localeMatcher'>;
|
|
68
69
|
|
|
70
|
+
declare class FormatError extends Error {
|
|
71
|
+
readonly code: ErrorCode;
|
|
72
|
+
constructor(msg: string, code: ErrorCode);
|
|
73
|
+
toString(): string;
|
|
74
|
+
}
|
|
75
|
+
|
|
69
76
|
export declare type FormatListOptions = Exclude<IntlListFormatOptions, 'localeMatcher'>;
|
|
70
77
|
|
|
71
78
|
export declare type FormatNumberOptions = Exclude<UnifiedNumberFormatOptions, 'localeMatcher'> & CustomFormatConfig;
|
|
@@ -95,20 +102,11 @@ export declare const FormattedDisplayName: React.FC<DisplayNamesOptions_2 & {
|
|
|
95
102
|
value: string | number | object;
|
|
96
103
|
}>;
|
|
97
104
|
|
|
98
|
-
export declare class FormattedHTMLMessage extends FormattedMessage<Record<string, PrimitiveType>> {
|
|
99
|
-
static displayName: string;
|
|
100
|
-
static defaultProps: {
|
|
101
|
-
tagName: "span";
|
|
102
|
-
values: {};
|
|
103
|
-
};
|
|
104
|
-
render(): JSX.Element;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
105
|
export declare const FormattedList: React.FC<IntlListFormatOptions & {
|
|
108
106
|
value: React.ReactNode[];
|
|
109
107
|
}>;
|
|
110
108
|
|
|
111
|
-
export declare class FormattedMessage<V extends Record<string, any> = Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn
|
|
109
|
+
export declare class FormattedMessage<T = React.ReactNode, V extends Record<string, any> = Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<T>>> extends React.Component<Props_3<V>> {
|
|
112
110
|
static displayName: string;
|
|
113
111
|
static defaultProps: {
|
|
114
112
|
values: {};
|
|
@@ -126,7 +124,7 @@ export declare const FormattedNumberParts: React.FC<Formatter['formatNumber'] &
|
|
|
126
124
|
children(val: Intl.NumberFormatPart[]): React.ReactElement | null;
|
|
127
125
|
}>;
|
|
128
126
|
|
|
129
|
-
export declare const FormattedPlural: React.ForwardRefExoticComponent<Pick<Props_2, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "
|
|
127
|
+
export declare const FormattedPlural: React.ForwardRefExoticComponent<Pick<Props_2, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "localeMatcher" | "format" | "type" | "value"> & {
|
|
130
128
|
forwardedRef?: ((instance: any) => void) | React.RefObject<any> | null | undefined;
|
|
131
129
|
} & React.RefAttributes<any>> & {
|
|
132
130
|
WrappedComponent: React.ComponentType<Props_2>;
|
|
@@ -179,7 +177,7 @@ declare interface Formatters_2 {
|
|
|
179
177
|
getPluralRules(...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;
|
|
180
178
|
}
|
|
181
179
|
|
|
182
|
-
declare type FormatXMLElementFn = (...args:
|
|
180
|
+
declare type FormatXMLElementFn<T> = (...args: Array<string | T>) => string | Array<string | T>;
|
|
183
181
|
|
|
184
182
|
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>> & {
|
|
185
183
|
WrappedComponent: React.ComponentType<P>;
|
|
@@ -207,12 +205,12 @@ export declare interface IntlConfig {
|
|
|
207
205
|
messages: Record<string, string> | Record<string, MessageFormatElement[]>;
|
|
208
206
|
defaultLocale: string;
|
|
209
207
|
defaultFormats: CustomFormats;
|
|
210
|
-
onError(err:
|
|
208
|
+
onError(err: ReactIntlError | FormatError): void;
|
|
211
209
|
}
|
|
212
210
|
|
|
213
211
|
export declare const IntlContext: React.Context<IntlShape>;
|
|
214
212
|
|
|
215
|
-
export declare interface IntlFormatters {
|
|
213
|
+
export declare interface IntlFormatters<T = React.ReactNode> {
|
|
216
214
|
formatDate(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
|
|
217
215
|
formatTime(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): string;
|
|
218
216
|
formatDateToParts(value: Parameters<Intl.DateTimeFormat['format']>[0] | string, opts?: FormatDateOptions): Intl.DateTimeFormatPart[];
|
|
@@ -222,8 +220,7 @@ export declare interface IntlFormatters {
|
|
|
222
220
|
formatNumberToParts(value: Parameters<Intl.NumberFormat['format']>[0], opts?: FormatNumberOptions): Intl.NumberFormatPart[];
|
|
223
221
|
formatPlural(value: Parameters<Intl.PluralRules['select']>[0], opts?: FormatPluralOptions): ReturnType<Intl.PluralRules['select']>;
|
|
224
222
|
formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType>): string;
|
|
225
|
-
formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn
|
|
226
|
-
formatHTMLMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType>): React.ReactNode;
|
|
223
|
+
formatMessage(descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | React.ReactElement | FormatXMLElementFn<T>>): string | React.ReactNodeArray;
|
|
227
224
|
formatList(values: Array<string>, opts?: FormatListOptions): string;
|
|
228
225
|
formatList(values: Array<string | React.ReactNode>, opts?: FormatListOptions): React.ReactNode;
|
|
229
226
|
formatDisplayName(value: Parameters<DisplayNames['of']>[0], opts?: FormatDisplayNameOptions): string | undefined;
|
|
@@ -263,9 +260,8 @@ declare class IntlMessageFormat {
|
|
|
263
260
|
private readonly message;
|
|
264
261
|
private readonly formatterCache;
|
|
265
262
|
constructor(message: string | MessageFormatElement[], locales?: string | string[], overrideFormats?: Partial<Formats>, opts?: Options);
|
|
266
|
-
format: (values?: Record<string,
|
|
267
|
-
formatToParts: (values?: Record<string,
|
|
268
|
-
formatHTMLMessage: (values?: Record<string, string | number | boolean | object | Date | FormatXMLElementFn | null | undefined> | undefined) => (string | object)[];
|
|
263
|
+
format: <T = void>(values?: Record<string, string | number | boolean | Date | T | FormatXMLElementFn<T> | null | undefined> | undefined) => string | T | (string | T)[];
|
|
264
|
+
formatToParts: <T>(values?: Record<string, string | number | boolean | Date | T | FormatXMLElementFn<T> | null | undefined> | undefined) => MessageFormatPart<T>[];
|
|
269
265
|
resolvedOptions: () => {
|
|
270
266
|
locale: string;
|
|
271
267
|
};
|
|
@@ -459,9 +455,9 @@ export declare interface MessageDescriptor {
|
|
|
459
455
|
defaultMessage?: string;
|
|
460
456
|
}
|
|
461
457
|
|
|
462
|
-
declare type MessageFormatElement = LiteralElement | ArgumentElement | NumberElement | DateElement | TimeElement | SelectElement | PluralElement | PoundElement;
|
|
458
|
+
declare type MessageFormatElement = LiteralElement | ArgumentElement | NumberElement | DateElement | TimeElement | SelectElement | PluralElement | TagElement | PoundElement;
|
|
463
459
|
|
|
464
|
-
declare type MessageFormatPart = LiteralPart_2 |
|
|
460
|
+
declare type MessageFormatPart<T> = LiteralPart_2 | ObjectPart<T>;
|
|
465
461
|
|
|
466
462
|
declare type NumberElement = SimpleFormatElement<TYPE.number, NumberSkeleton>;
|
|
467
463
|
|
|
@@ -484,6 +480,11 @@ declare interface NumberSkeletonToken {
|
|
|
484
480
|
options: string[];
|
|
485
481
|
}
|
|
486
482
|
|
|
483
|
+
declare interface ObjectPart<T = any> {
|
|
484
|
+
type: PART_TYPE.object;
|
|
485
|
+
value: T;
|
|
486
|
+
}
|
|
487
|
+
|
|
487
488
|
export declare type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
|
|
488
489
|
|
|
489
490
|
declare type OptionalIntlConfig = Omit<IntlConfig, keyof typeof DEFAULT_INTL_CONFIG> & Partial<typeof DEFAULT_INTL_CONFIG>;
|
|
@@ -522,7 +523,7 @@ declare type Part_2 = LiteralPart | ElementPart;
|
|
|
522
523
|
|
|
523
524
|
declare const enum PART_TYPE {
|
|
524
525
|
literal = 0,
|
|
525
|
-
|
|
526
|
+
object = 1
|
|
526
527
|
}
|
|
527
528
|
|
|
528
529
|
declare interface PluralElement extends BaseElement<TYPE.plural> {
|
|
@@ -570,6 +571,19 @@ declare interface Props_3<V extends Record<string, any> = Record<string, React.R
|
|
|
570
571
|
|
|
571
572
|
export declare const RawIntlProvider: React.Provider<IntlShape>;
|
|
572
573
|
|
|
574
|
+
export declare class ReactIntlError extends Error {
|
|
575
|
+
code: ReactIntlErrorCode;
|
|
576
|
+
constructor(code: ReactIntlErrorCode, message: string, exception?: Error);
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
export declare const enum ReactIntlErrorCode {
|
|
580
|
+
FORMAT_ERROR = "FORMAT_ERROR",
|
|
581
|
+
UNSUPPORTED_FORMATTER = "UNSUPPORTED_FORMATTER",
|
|
582
|
+
INVALID_CONFIG = "INVALID_CONFIG",
|
|
583
|
+
MISSING_DATA = "MISSING_DATA",
|
|
584
|
+
MISSING_TRANSLATION = "MISSING_TRANSLATION"
|
|
585
|
+
}
|
|
586
|
+
|
|
573
587
|
declare type RelativeTimeData = {
|
|
574
588
|
[u in LDMLPluralRule]?: string;
|
|
575
589
|
};
|
|
@@ -679,6 +693,13 @@ declare interface State_2 {
|
|
|
679
693
|
currentValueInSeconds: number;
|
|
680
694
|
}
|
|
681
695
|
|
|
696
|
+
declare interface TagElement {
|
|
697
|
+
type: TYPE.tag;
|
|
698
|
+
value: string;
|
|
699
|
+
children: MessageFormatElement[];
|
|
700
|
+
location?: Location;
|
|
701
|
+
}
|
|
702
|
+
|
|
682
703
|
declare type TimeElement = SimpleFormatElement<TYPE.time, DateTimeSkeleton>;
|
|
683
704
|
|
|
684
705
|
declare enum TYPE {
|
|
@@ -714,21 +735,41 @@ declare enum TYPE {
|
|
|
714
735
|
* Only possible within plural argument.
|
|
715
736
|
* This is the `#` symbol that will be substituted with the count.
|
|
716
737
|
*/
|
|
717
|
-
pound = 7
|
|
738
|
+
pound = 7,
|
|
739
|
+
/**
|
|
740
|
+
* XML-like tag
|
|
741
|
+
*/
|
|
742
|
+
tag = 8
|
|
718
743
|
}
|
|
719
744
|
|
|
720
745
|
declare type UnifiedNumberFormatOptions = Intl.NumberFormatOptions & NumberFormatDigitOptions & {
|
|
721
|
-
localeMatcher?:
|
|
722
|
-
style?:
|
|
723
|
-
compactDisplay?:
|
|
724
|
-
currencyDisplay?:
|
|
725
|
-
currencySign?:
|
|
726
|
-
notation?:
|
|
727
|
-
signDisplay?:
|
|
746
|
+
localeMatcher?: UnifiedNumberFormatOptionsLocaleMatcher;
|
|
747
|
+
style?: UnifiedNumberFormatOptionsStyle;
|
|
748
|
+
compactDisplay?: UnifiedNumberFormatOptionsCompactDisplay;
|
|
749
|
+
currencyDisplay?: UnifiedNumberFormatOptionsCurrencyDisplay;
|
|
750
|
+
currencySign?: UnifiedNumberFormatOptionsCurrencySign;
|
|
751
|
+
notation?: UnifiedNumberFormatOptionsNotation;
|
|
752
|
+
signDisplay?: UnifiedNumberFormatOptionsSignDisplay;
|
|
728
753
|
unit?: Unit_2;
|
|
729
|
-
unitDisplay?:
|
|
754
|
+
unitDisplay?: UnifiedNumberFormatOptionsUnitDisplay;
|
|
730
755
|
};
|
|
731
756
|
|
|
757
|
+
declare type UnifiedNumberFormatOptionsCompactDisplay = 'short' | 'long';
|
|
758
|
+
|
|
759
|
+
declare type UnifiedNumberFormatOptionsCurrencyDisplay = 'symbol' | 'code' | 'name' | 'narrowSymbol';
|
|
760
|
+
|
|
761
|
+
declare type UnifiedNumberFormatOptionsCurrencySign = 'standard' | 'accounting';
|
|
762
|
+
|
|
763
|
+
declare type UnifiedNumberFormatOptionsLocaleMatcher = 'lookup' | 'best fit';
|
|
764
|
+
|
|
765
|
+
declare type UnifiedNumberFormatOptionsNotation = 'standard' | 'scientific' | 'engineering' | 'compact';
|
|
766
|
+
|
|
767
|
+
declare type UnifiedNumberFormatOptionsSignDisplay = 'auto' | 'always' | 'never' | 'exceptZero';
|
|
768
|
+
|
|
769
|
+
declare type UnifiedNumberFormatOptionsStyle = 'decimal' | 'percent' | 'currency' | 'unit';
|
|
770
|
+
|
|
771
|
+
declare type UnifiedNumberFormatOptionsUnitDisplay = 'long' | 'short' | 'narrow';
|
|
772
|
+
|
|
732
773
|
declare type Unit = 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year';
|
|
733
774
|
|
|
734
775
|
declare type Unit_2 = 'degree' | 'acre' | 'hectare' | 'percent' | 'bit' | 'byte' | 'gigabit' | 'gigabyte' | 'kilobit' | 'kilobyte' | 'megabit' | 'megabyte' | 'petabyte' | 'terabit' | 'terabyte' | 'day' | 'hour' | 'millisecond' | 'minute' | 'month' | 'second' | 'week' | 'year' | 'centimeter' | 'foot' | 'inch' | 'kilometer' | 'meter' | 'mile-scandinavian' | 'mile' | 'millimeter' | 'yard' | 'gram' | 'kilogram' | 'ounce' | 'pound' | 'stone' | 'celsius' | 'fahrenheit' | 'fluid-ounce' | 'gallon' | 'liter' | 'milliliter';
|