@progress/kendo-react-intl
Version:
React Internationalization package provides services for parsing and formatting of dates and numbers. KendoReact Internationalization package
309 lines (283 loc) • 11.6 kB
TypeScript
/**
* @license
*-------------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the package root for more information
*-------------------------------------------------------------------------------------------
*/
import { DateFieldNameOptions } from '@progress/kendo-intl';
import { DateFormatNameOptions } from '@progress/kendo-intl';
import { DateFormatOptions } from '@progress/kendo-intl';
import { DateFormatPart } from '@progress/kendo-intl';
import { default as default_2 } from 'prop-types';
import { default as default_3 } from 'react';
import { JSX } from 'react/jsx-runtime';
import { NumberFormatOptions } from '@progress/kendo-intl';
import * as React_2 from 'react';
export { DateFieldNameOptions }
export { DateFormatNameOptions }
export { DateFormatOptions }
export { DateFormatPart }
/** @hidden */
export declare const GlobalizationContext: React_2.Context<GlobalizationContextType>;
/** @hidden */
declare type GlobalizationContextType = {
intl: IntlService;
localization: LocalizationService;
};
/**
* A React component which provides an internationalization service. Expects a locale string as a property of the component.
*/
export declare class IntlProvider extends React_2.Component<IntlProviderProps, {}> {
/**
* @hidden
*/
static propTypes: {
locale: default_2.Requireable<string>;
};
/**
* Returns an internationalization service. The method is suitable for overriding when you implement custom internationalization behavior.
*/
getIntlService(): IntlService;
/**
* @hidden
*/
render(): JSX.Element;
}
/**
* Represents the props of the KendoReact IntlProvider component.
*/
export declare interface IntlProviderProps {
/**
* The locale that will be used by the child components.
*/
locale: string;
/**
* @hidden
*/
children?: React.ReactNode;
}
/**
* A service which provides internationalization methods and is bound to a specific locale.
*/
export declare class IntlService {
locale: string;
/**
* Creates a new instance of the internationalization service.
*
* @param locale - The locale that will be used by the internationalization methods.
*/
constructor(locale: string);
/**
* Formats a string with placeholders such as `Total amount {0:c}`.
*
* @param format - The format string.
* @param values - One or more values to output in the format string placeholders.
* @return - The formatted string.
*/
format(format: string, ...values: any[]): string;
/**
* Converts a `Date` object to a string based on the specified format. If no format is provided, the default short date format is used.
*
* @param value - The date which will be formatted.
* @param format - The format string or options.
* @return - The formatted date.
*/
formatDate(value: Date, format?: string | DateFormatOptions): string;
/**
* Converts an object to a string based on the specified format.
*
* @param value - The value which will be formatted.
* @param format - The format to use.
* @return - The formatted object.
*/
toString(value: any, format: string | any): string;
/**
* Converts a string to a `Number`.
*
* @param value - The string which will be parsed.
* @param format - The format string or options.
* @return - The parsed number.
*/
parseNumber(value: string, format?: string | NumberFormatOptions): number;
/**
* Converts a string to a `Date` object based on the specified format.
*
* @param value - The string which will be converted.
* @param format - The format strings or options.
* @return - The parsed date.
*/
parseDate(value: string, format?: string | DateFormatOptions | string[] | DateFormatOptions[]): Date;
/**
* Converts a `Number` to a string based on the specified format.
*
* @param value - The number which will be formatted.
* @param format - The format string or options.
* @return - The formatted number.
*/
formatNumber(value: number, format: string | NumberFormatOptions): string;
/**
* Returns a localized date field name based on specific `dateFieldName` options.
*
* @param options - The detailed configuration for the desired date field name.
* @returns - The localized date field name from the current locale based on the option.
*/
dateFieldName(options: DateFieldNameOptions): string;
/**
* Returns the day names from the current locale based on the option.
*
* @param options - The detailed configuration for the desired date format.
* @return - The day names from the current locale based on the option.
*/
dateFormatNames(options: DateFormatNameOptions): any;
/**
* Splits the date format into objects which contain information about each part of the pattern.
*
* @param format - The format string or options.
* @returns - The date format parts.
*/
splitDateFormat(format: string | DateFormatOptions): DateFormatPart[];
/**
* Returns the number symbols from the current locale.
*
* @return - The number symbols from the current locale.
*/
numberSymbols(): any;
/**
* Returns the first day index, starting from Sunday.
*
* @return - The index of the first day of the week (0 == Sunday).
*/
firstDay(): number;
/**
* @hidden
*/
localeInfo(): any;
/**
* @hidden
*/
localeCurrency(): any;
}
/**
* Loads CLDR data.
*
* @param data - The CLDR data to be loaded. Accepts multiple parameters.
*/
export declare const load: (...data: any[]) => void;
/**
* Provides mechanism to load language-specific messages for the KendoReact components.
*
* @param messages - An iterable object which contains key-value pairs.
* @param languages - The language to which the messages are associated.
*/
export declare function loadMessages(messages: any, language: string): void;
/**
* @hidden
*/
export declare const localizationMessages: any;
/**
* A React component which provides a localization service. Expects a language string as a property of the component.
*/
export declare class LocalizationProvider extends React_2.Component<LocalizationProviderProps, {}> {
/**
* @hidden
*/
static propTypes: {
language: default_2.Requireable<string>;
};
/**
* Returns a localization service. The method is suitable for overriding when you implement custom localization behavior.
*/
getLocalizationService(): LocalizationService;
/**
* @hidden
*/
render(): JSX.Element;
}
/**
* Represents the props of the KendoReact LocalizationProvider component.
*/
export declare interface LocalizationProviderProps {
/**
* The language that will be used by the child components.
*/
language: string;
/**
* @hidden
*/
children?: React.ReactNode;
}
/**
* A service which provides localization methods.
*/
export declare class LocalizationService {
/**
* The language code used for localization. When no string is available for this language, the default value is returned.
*/
language?: string;
/**
* Creates a new LocalizationService instance.
*
* @param language The language code for localization.
*/
constructor(language?: string);
/**
* Provides a string based on a key for the current language. When no string for the current language is available under this key, the `defaultValue` is returned.
*
* @param key - The key which identifies the string for the current language.
* @param defaultValue - The default value which will be returned when no string
* for the current language is available under the key.
* @return - The string for the current language.
*/
toLanguageString(key: string, defaultValue: string): string;
}
export { NumberFormatOptions }
/**
* Provides an internationalization service. When the passed component is a direct or indirect child of `IntlProvider`, the returned service uses the locale of the provider. Otherwise, uses `en` as a default locale. To handle locale changes, call the method on each `render`.
*
* @param componentClass - The React component class that will use the internationalization service.
*/
export declare function provideIntlService(component: React_2.Component): IntlService;
/**
* Provides a localization service. When the passed component is a direct or indirect child of `LocalizationProvider`, the returned service uses the language of the provider. To handle locale changes, call the method on each `render`.
*
* @param componentClass - The React component class that will use the internationalization service.
*/
export declare function provideLocalizationService(component: React_2.Component): LocalizationService;
/**
* A method which registers a component class or a functional stateless component for internationalization. When a component of that type is a direct or indirect child of `IntlProvider`, the locale of the provider is used. Otherwise, uses `en` as a default locale.
*
* @param component - The React component class that will use the internationalization methods.
*/
export declare function registerForIntl(component: React_2.ComponentClass<any, any>): void;
/**
* A method which registers a component class or a stateless functional component for localization. When a component of that type is a direct or indirect child of `LocalizationProvider`, the language of the provider is used.
*
* @param component - The React component class that will use the internationalization methods.
*/
export declare function registerForLocalization(component: React_2.ComponentClass<any, any>): void;
/**
* @hidden
* Assembles all necessary parts for both localization and internationalization to work in a server/client environments.
* Combined in a single `ServerGlobalization` component for convenience.
* From everything that has been loaded on the server, only pass what's necessary to the client, which is loaded on the client by the `DataProvider`s.
* This would result in minimal amount of data being transferred to the client.
*/
export declare const ServerGlobalization: (props: ServerGlobalizationProps) => JSX.Element;
/**
* @hidden Currently used only externally through the ServerGlobalization of the Grid.
*/
export declare type ServerGlobalizationProps = {
locale?: string;
language?: string;
children?: default_3.ReactNode;
};
/**
* A custom [React Hook](https://react.dev/reference/react/hooks) providing access to an [IntlService]({% slug api_intl_intlservice %}).
*/
export declare const useInternationalization: () => IntlService;
/**
* A custom [React Hook](https://react.dev/reference/react/hooks) providing access to an [LocalizationService]({% slug api_intl_localizationservice %}).
*/
export declare const useLocalization: () => LocalizationService;
export { }