react-intl
Version:
Internationalize React apps. This library provides React components and an API to format dates, numbers, and strings, including pluralization and handling translations.
247 lines • 15.3 kB
TypeScript
import * as React from "react";
import { CreateIntlFn, CustomFormatConfig, CustomFormatConfig as CustomFormatConfig$1, CustomFormats, FormatDateOptions, FormatDateOptions as FormatDateOptions$1, FormatDateTimeRangeOptions, FormatDisplayNameOptions, FormatDisplayNameOptions as FormatDisplayNameOptions$1, FormatDurationOptions, FormatDurationOptions as FormatDurationOptions$1, FormatListOptions, FormatListOptions as FormatListOptions$1, FormatNumberOptions, FormatNumberOptions as FormatNumberOptions$1, FormatPluralOptions, FormatPluralOptions as FormatPluralOptions$1, FormatRelativeTimeOptions, FormatRelativeTimeOptions as FormatRelativeTimeOptions$1, FormatTimeOptions, FormattedText, Formatters, Formatters as Formatters$1, IntlCache, IntlError as ReactIntlError, IntlErrorCode as ReactIntlErrorCode, IntlFormatters, IntlFormatters as IntlFormatters$1, InvalidConfigError, MessageArgumentsFromCatalog, MessageDescriptor, MessageDescriptor as MessageDescriptor$1, MessageFormatError, MessageTag, MessageTextOutput, MessageTextOutput as MessageTextOutput$1, MessageValue, MessageValues, MessageValuesOf, MessageValuesOf as MessageValuesOf$1, MissingDataError, MissingTranslationError, RegisteredMessageId, RegisteredMessageValues, ResolvedIntlConfig as ResolvedIntlConfig$1, TextMessageFormatter, TypedMessageArguments, TypedMessageDescriptor, TypedMessageDescriptor as TypedMessageDescriptor$1, UnregisteredMessageDescriptor, UnsupportedFormatterError, UntypedMessageDescriptor, createIntlCache, defineMessages } from "@formatjs/intl";
import { FormatXMLElementFn, Options, PrimitiveType, PrimitiveType as PrimitiveType$1 } from "intl-messageformat";
import { MessageFormatElement } from "@formatjs/icu-messageformat-parser";
//#region packages/ecma402-abstract/types/number.d.ts
type NumberFormatNotation = "standard" | "scientific" | "engineering" | "compact";
type RoundingPriorityType = "auto" | "morePrecision" | "lessPrecision";
type RoundingModeType = "ceil" | "floor" | "expand" | "trunc" | "halfCeil" | "halfFloor" | "halfExpand" | "halfTrunc" | "halfEven";
type UseGroupingType = "min2" | "auto" | "always" | boolean;
interface NumberFormatDigitOptions {
minimumIntegerDigits?: number;
minimumSignificantDigits?: number;
maximumSignificantDigits?: number;
minimumFractionDigits?: number;
maximumFractionDigits?: number;
roundingPriority?: RoundingPriorityType;
roundingIncrement?: number;
roundingMode?: RoundingModeType;
trailingZeroDisplay?: TrailingZeroDisplay;
}
type NumberFormatOptionsLocaleMatcher = "lookup" | "best fit";
type NumberFormatOptionsStyle = "decimal" | "percent" | "currency" | "unit";
type NumberFormatOptionsCompactDisplay = "short" | "long";
type NumberFormatOptionsCurrencyDisplay = "symbol" | "code" | "name" | "narrowSymbol";
type NumberFormatOptionsCurrencySign = "standard" | "accounting";
type NumberFormatOptionsNotation = NumberFormatNotation;
type NumberFormatOptionsSignDisplay = "auto" | "always" | "never" | "exceptZero" | "negative";
type NumberFormatOptionsUnitDisplay = "long" | "short" | "narrow";
type TrailingZeroDisplay = "auto" | "stripIfInteger";
type NumberFormatOptions = Omit<Intl.NumberFormatOptions, "signDisplay" | "useGrouping"> & NumberFormatDigitOptions & {
localeMatcher?: NumberFormatOptionsLocaleMatcher;
style?: NumberFormatOptionsStyle;
compactDisplay?: NumberFormatOptionsCompactDisplay;
currencyDisplay?: NumberFormatOptionsCurrencyDisplay;
currencySign?: NumberFormatOptionsCurrencySign;
notation?: NumberFormatOptionsNotation;
signDisplay?: NumberFormatOptionsSignDisplay;
unit?: string;
unitDisplay?: NumberFormatOptionsUnitDisplay;
numberingSystem?: string;
trailingZeroDisplay?: TrailingZeroDisplay;
roundingPriority?: RoundingPriorityType;
roundingIncrement?: number;
roundingMode?: RoundingModeType;
useGrouping?: UseGroupingType;
};
//#endregion
//#region packages/react-intl/utils.d.ts
type DefaultIntlConfig = Pick<ResolvedIntlConfig, "fallbackOnEmptyString" | "formats" | "messages" | "timeZone" | "textComponent" | "defaultLocale" | "defaultFormats" | "onError">;
declare const DEFAULT_INTL_CONFIG$1: DefaultIntlConfig;
//#endregion
//#region packages/react-intl/types.d.ts
type IntlConfig = Omit<ResolvedIntlConfig, keyof typeof DEFAULT_INTL_CONFIG$1> & Partial<typeof DEFAULT_INTL_CONFIG$1>;
interface ResolvedIntlConfig extends ResolvedIntlConfig$1<React.ReactNode> {
textComponent?: React.ComponentType | keyof React.JSX.IntrinsicElements;
wrapRichTextChunksInFragment?: boolean;
}
interface IntlShape extends ResolvedIntlConfig, IntlFormatters$1<React.ReactNode> {
formatMessage<V extends MessageValues = never, T extends React.ReactNode = React.ReactNode>(this: void, descriptor: [V] extends [never] ? never : UntypedMessageDescriptor, ...args: TypedMessageArguments<NoInfer<V>, string, T>): MessageTextOutput$1;
formatMessage<V extends MessageValues = never, T extends React.ReactNode = React.ReactNode>(this: void, descriptor: [V] extends [never] ? never : UntypedMessageDescriptor, ...args: TypedMessageArguments<NoInfer<V>, T>): string | T | Array<string | T>;
formatMessage<D extends TypedMessageDescriptor$1<MessageValues>>(this: void, descriptor: D, ...args: TypedMessageArguments<MessageValuesOf$1<NoInfer<D>>, string, React.ReactNode>): MessageTextOutput$1;
formatMessage<D extends TypedMessageDescriptor$1<MessageValues>>(this: void, descriptor: D, ...args: TypedMessageArguments<MessageValuesOf$1<NoInfer<D>>, React.ReactNode>): React.ReactNode;
formatMessage<const K extends RegisteredMessageId>(this: void, descriptor: UntypedMessageDescriptor & {
id: K;
}, ...args: TypedMessageArguments<RegisteredMessageValues<NoInfer<K>>, string, React.ReactNode>): MessageTextOutput$1;
formatMessage<const K extends RegisteredMessageId>(this: void, descriptor: UntypedMessageDescriptor & {
id: K;
}, ...args: TypedMessageArguments<RegisteredMessageValues<NoInfer<K>>, React.ReactNode>): string | React.ReactNode | Array<string | React.ReactNode>;
formatMessage<V = never, const D extends UntypedMessageDescriptor = UntypedMessageDescriptor>(this: void, descriptor: [V] extends [never] ? D & UnregisteredMessageDescriptor<NoInfer<D>> : never, values?: Record<string, PrimitiveType$1 | FormatXMLElementFn<string, string>>, opts?: Options): MessageTextOutput$1;
formatMessage<V = never, const D extends UntypedMessageDescriptor = UntypedMessageDescriptor>(this: void, descriptor: [V] extends [never] ? D & UnregisteredMessageDescriptor<NoInfer<D>> : never, values?: Record<string, React.ReactNode | PrimitiveType$1 | FormatXMLElementFn<string, React.ReactNode>>, opts?: Options): Array<React.ReactNode>;
$t: IntlShape["formatMessage"];
formatters: Formatters$1;
}
//#endregion
//#region packages/react-intl/components/createIntl.d.ts
/**
* Create intl object
* @param config intl config
* @param cache cache for formatter instances to prevent memory leak
*/
export declare const createIntl: CreateIntlFn<React.ReactNode, IntlConfig, IntlShape>;
//#endregion
//#region packages/react-intl/components/context.d.ts
declare const IntlContext: React.Context<IntlShape>;
declare const Provider: React.Provider<IntlShape>;
//#endregion
//#region packages/react-intl/components/dateTimeRange.d.ts
interface Props$3 extends FormatDateTimeRangeOptions {
from: Parameters<Intl.DateTimeFormat["formatRange"]>[0];
to: Parameters<Intl.DateTimeFormat["formatRange"]>[1];
children?(value: React.ReactNode): React.ReactElement | null;
}
declare const FormattedDateTimeRange: React.FC<Props$3>;
//#endregion
//#region packages/react-intl/components/message.d.ts
interface Props$2<V extends Record<string, any> = Record<string, React.ReactNode | PrimitiveType$1 | FormatXMLElementFn<React.ReactNode>>> extends UntypedMessageDescriptor, MessagePresentationProps {
values?: V;
}
interface MessagePresentationProps {
tagName?: React.ElementType<any>;
children?(nodes: React.ReactNode[]): React.ReactNode | null;
ignoreTag?: Options["ignoreTag"];
}
type TypedProps<V extends MessageValues> = TypedMessageDescriptor$1<V> & MessagePresentationProps & ([] extends TypedMessageArguments<V, React.ReactNode> ? {
values?: TypedMessageArguments<NoInfer<V>, React.ReactNode>[0];
} : {
values: TypedMessageArguments<NoInfer<V>, React.ReactNode>[0];
});
interface FormattedMessageComponent {
<V extends MessageValues>(props: TypedProps<V>): React.ReactNode;
(props: Props$2): React.ReactNode;
displayName?: string;
}
declare const MemoizedFormattedMessage: FormattedMessageComponent;
//#endregion
//#region packages/react-intl/components/plural.d.ts
interface Props$1 extends FormatPluralOptions$1 {
value: number;
other: React.ReactNode;
zero?: React.ReactNode;
one?: React.ReactNode;
two?: React.ReactNode;
few?: React.ReactNode;
many?: React.ReactNode;
children?(value: React.ReactNode): React.ReactElement | null;
}
declare const FormattedPlural: React.FC<Props$1>;
//#endregion
//#region packages/react-intl/components/provider.d.ts
declare const IntlProvider: React.FC<React.PropsWithChildren<IntlConfig>>;
//#endregion
//#region packages/react-intl/components/relative.d.ts
interface Props extends FormatRelativeTimeOptions$1 {
value?: number;
unit?: Intl.RelativeTimeFormatUnit;
updateIntervalInSeconds?: number;
children?(value: string): React.ReactElement | null;
}
declare const FormattedRelativeTime: React.FC<Props>;
//#endregion
//#region packages/react-intl/components/useIntl.d.ts
declare function useIntl(this: void): IntlShape;
//#endregion
//#region packages/react-intl/components/createFormattedComponent.d.ts
type Formatter = {
formatDate: FormatDateOptions$1;
formatTime: FormatDateOptions$1;
formatNumber: FormatNumberOptions$1;
formatList: FormatListOptions$1;
formatDuration: FormatDurationOptions$1;
formatDisplayName: FormatDisplayNameOptions$1;
};
export declare const FormattedNumberParts: React.FC<Formatter["formatNumber"] & {
value: Parameters<IntlShape["formatNumber"]>[0];
children(val: Intl.NumberFormatPart[]): React.ReactElement | null;
}>;
export declare const FormattedDurationParts: React.FC<FormatDurationOptions$1 & {
value: Parameters<IntlShape["formatDuration"]>[0];
children(val: ReturnType<IntlShape["formatDurationToParts"]>): React.ReactElement | null;
}>;
export declare const FormattedListParts: React.FC<Formatter["formatList"] & {
value: Parameters<IntlShape["formatList"]>[0];
children(val: ReturnType<Intl.ListFormat["formatToParts"]>): React.ReactElement | null;
}>;
//#endregion
//#region packages/react-intl/define-message.d.ts
export declare function defineMessage<V extends MessageValues = {}, const D extends MessageDescriptor$1 = never>(message: D, options?: {
typed: true;
}): Readonly<D> & Omit<TypedMessageDescriptor$1<NoInfer<V>>, keyof D>;
export declare function defineMessage<V extends MessageValues = {}>(message: MessageDescriptor$1 & {
id: NonNullable<MessageDescriptor$1["id"]>;
defaultMessage: string;
}, options?: {
typed: true;
}): TypedMessageDescriptor$1<NoInfer<V>> & Readonly<{
id: NonNullable<MessageDescriptor$1["id"]>;
defaultMessage: string;
}>;
export declare function defineMessage<V extends MessageValues = {}>(message: MessageDescriptor$1 & {
id: NonNullable<MessageDescriptor$1["id"]>;
defaultMessage: NonNullable<MessageDescriptor$1["defaultMessage"]>;
}, options?: {
typed: true;
}): TypedMessageDescriptor$1<NoInfer<V>> & Readonly<{
id: NonNullable<MessageDescriptor$1["id"]>;
defaultMessage: NonNullable<MessageDescriptor$1["defaultMessage"]>;
}>;
export declare function defineMessage<V extends MessageValues = {}>(message: MessageDescriptor$1 & {
defaultMessage: string;
}, options?: {
typed: true;
}): TypedMessageDescriptor$1<NoInfer<V>> & Readonly<{
defaultMessage: string;
}>;
export declare function defineMessage<V extends MessageValues = {}>(message: MessageDescriptor$1 & {
defaultMessage: NonNullable<MessageDescriptor$1["defaultMessage"]>;
}, options?: {
typed: true;
}): TypedMessageDescriptor$1<NoInfer<V>> & Readonly<{
defaultMessage: NonNullable<MessageDescriptor$1["defaultMessage"]>;
}>;
export declare function defineMessage<V extends MessageValues = {}>(message: MessageDescriptor$1 & {
id: NonNullable<MessageDescriptor$1["id"]>;
}, options?: {
typed: true;
}): TypedMessageDescriptor$1<NoInfer<V>> & Readonly<{
id: NonNullable<MessageDescriptor$1["id"]>;
}>;
export declare function defineMessage<V extends MessageValues = {}>(message: MessageDescriptor$1, options?: {
typed: true;
}): TypedMessageDescriptor$1<NoInfer<V>>;
export declare function defineMessage<T extends MessageDescriptor$1>(message: T): Readonly<T>;
//#endregion
//#region packages/react-intl/index.d.ts
export declare const FormattedDate: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig$1<"date"> & {
value: string | number | Date | undefined;
children?(formattedDate: string): React.ReactElement | null;
}>;
export declare const FormattedTime: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig$1<"time"> & {
value: string | number | Date | undefined;
children?(formattedTime: string): React.ReactElement | null;
}>;
export declare const FormattedNumber: React.FC<Omit<NumberFormatOptions, "localeMatcher"> & CustomFormatConfig$1<"number"> & {
value: Parameters<IntlShape["formatNumber"]>[0];
children?(formattedNumber: string): React.ReactElement | null;
}>;
export declare const FormattedDuration: React.FC<FormatDurationOptions$1 & {
value: Parameters<IntlShape["formatDuration"]>[0];
children?(formattedDuration: string): React.ReactElement | null;
}>;
export declare const FormattedList: React.FC<Intl.ListFormatOptions & {
value: Parameters<IntlShape["formatList"]>[0];
}>;
export declare const FormattedDisplayName: React.FC<Intl.DisplayNamesOptions & {
value: string;
}>;
export declare const FormattedDateParts: React.FC<FormatDateOptions$1 & {
value: Parameters<Intl.DateTimeFormat["format"]>[0] | string;
children(val: Intl.DateTimeFormatPart[]): React.ReactElement | null;
}>;
export declare const FormattedTimeParts: React.FC<FormatTimeOptions & {
value: Parameters<Intl.DateTimeFormat["format"]>[0] | string;
children(val: Intl.DateTimeFormatPart[]): React.ReactElement | null;
}>;
//#endregion
export { type CustomFormatConfig, type CustomFormats, type FormatDateOptions, type FormatDisplayNameOptions, type FormatDurationOptions, type FormatListOptions, type FormatNumberOptions, type FormatPluralOptions, type FormatRelativeTimeOptions, FormattedDateTimeRange, MemoizedFormattedMessage as FormattedMessage, FormattedPlural, FormattedRelativeTime, type FormattedText, type Formatters, type IntlCache, type IntlConfig, IntlContext, type IntlFormatters, IntlProvider, type IntlShape, InvalidConfigError, type MessageArgumentsFromCatalog, type MessageDescriptor, type MessageFormatElement, MessageFormatError, type MessageTag, type MessageTextOutput, type MessageValue, type MessageValuesOf, MissingDataError, MissingTranslationError, type PrimitiveType, Provider as RawIntlProvider, ReactIntlError, ReactIntlErrorCode, type ResolvedIntlConfig, type TextMessageFormatter, type TypedMessageDescriptor, UnsupportedFormatterError, createIntlCache, defineMessages, useIntl };
//# sourceMappingURL=index.d.ts.map