import { InulaElement, FunctionComponent, Key } from 'openinula'; /** * 定义一个时间触发器类,使用泛型实现动态时间的监听 */ declare class EventDispatcher> { private _events; constructor(); /** * on 方法,向指定的事件添加监听器,并返回一个用于移除该监听器的函数 * @param event * @param listener */ on(event: keyof E, listener: E[keyof E]): () => void; /** * removeListener 方法,移除指定事件的监听器 * @param event * @param listener */ removeListener(event: keyof E, listener: E[keyof E]): void; /** * emit 方法,触发指定事件,并按照监听器注册顺序执行监听器 * @param event * @param args */ emit(event: keyof E, ...args: Parameters): void; } declare class I18n extends EventDispatcher { locale: Locale; locales: Locales; defaultLocale?: Locale; timeZone?: string; allMessages: AllMessages; private readonly _localeConfig; readonly onError?: Error; readonly cache?: I18nCache; $t: (id: MessageDescriptor | string, values?: Record | undefined, { messages, context, formatOptions }?: MessageOptions) => string | any[] | MessageDescriptor; constructor(props: I18nProps); get messages(): string | Messages | AllMessages; get localeConfig(): LocaleConfig; setLocaleConfig(locale: Locale, localeData: LocaleConfig): void; loadLocaleConfig(localeOrAllData: Locale | AllLocaleConfig, localeConfig?: LocaleConfig): void; setMessage(locale: Locale, messages: Messages): void; changeMessage(messages: AllMessages): void; loadMessage(localeOrMessages: Locale | AllMessages | undefined, messages?: Messages): void; changeLanguage(locale: Locale, locales?: Locales): void; formatMessage(id: MessageDescriptor | string, values?: Record | undefined, { messages, context, formatOptions }?: MessageOptions): string | any[] | MessageDescriptor; formatDate(value: string | Date, formatOptions?: Intl.DateTimeFormatOptions): string; formatNumber(value: number, formatOptions?: Intl.NumberFormatOptions): string; } type I18nOptions = { locale?: Locale; messages?: AllMessages; dateTimeFormats?: NonNullable; datetimeFormats?: NonNullable; numberFormats?: NonNullable; silentTranslationWarn?: boolean; globalInjection?: boolean; legacy?: false; install?: Function; }; type UseI18nOptions = { options?: Options; Locales?: string | NonNullable; } & I18nOptions; type Options = { message?: unknown; datetime?: unknown; number?: unknown; }; type PathValue = PathValueObject | PathValueArray | Function | string | number | boolean | null; type PathValueObject = { [key: string]: PathValue; }; type PathValueArray = Array; interface App { rootComponent: InulaElement; component(name: string, component: FunctionComponent): void; } declare class I18nPath { private _cache; /** * External parse that check for a cache hit first */ parsePath(path: string): string[]; getPathValue(obj: string | Messages | AllMessages, id: string): PathValue; } declare class VueI18n extends I18n { locale: Locale; localMessages: Map; dateTimeFormats?: NonNullable; datetimeFormats?: NonNullable; numberFormats?: NonNullable; vueMessages: string | AllMessages; path?: I18nPath; listeners?: any; constructor(options: I18nOptions); get messages(): string | Messages | AllMessages; setLocalMessage: (componentId: string, messages: AllMessages) => void; loadMessage: (localeOrMessages: Locale | AllMessages | undefined, messages?: Messages, componentId?: string) => void; changeLanguage: (locale: Locale) => void; changeMessage: (messages: AllMessages) => void; $t: (msgKey: string, values?: any, componentId?: string) => string | any[] | MessageDescriptor; /** * 用于处理局部组件内的messages * @param componentId * @private */ private getComponentMessages; $n: (value: number, ...args: any) => string; $d: (value: DatePool, ...args: any) => string; install: (app: App) => void; } interface FormattedMessageProps extends MessageDescriptor { values?: Record; tagName?: string; children?(nodes: any[]): any; } interface MessageDescriptor extends MessageOptions { id: string; defaultMessage?: string; defaultValues?: Record; } interface MessageOptions { comment?: string; messages?: string; context?: string; formatOptions?: FormatOptions; } interface I18nCache { dateTimeFormat: Record; numberFormat: Record; plurals: Record; select: Record; octothorpe: Record; } interface RichText { components?: { [key: string]: InulaNode; }; } interface InulaPortal extends InulaElement { key: Key | null; children: InulaNode; } type I18nProps = RichText & { locale?: Locale; locales?: Locales; messages?: AllMessages; defaultLocale?: string; timeZone?: string; localeConfig?: AllLocaleConfig; cache?: I18nCache; onError?: Error; }; interface FormatOptions { dateTimeFormat?: Intl.DateTimeFormatOptions; numberFormat?: Intl.NumberFormatOptions; plurals?: Intl.PluralRulesOptions; } interface InjectOptions { isUsingForwardRef?: boolean; ensureContext?: boolean; } interface I18nContextProps { i18n?: I18n | VueI18n; } type configProps = I18nProps & { RenderOnLocaleChange?: boolean; children?: any; onWarn?: Error; }; interface MissingMessageEvent { locale: Locale; id: string; context?: string; } type Error = string | ((message: any, id: any, context: any) => string); type Locale = string; type Locales = Locale | Locale[]; type MyFunctionType any> = T; type LocaleConfig = { plurals?: MyFunctionType; }; type AllLocaleConfig = Record; type CompiledMessagePart = string | Array | Record>; type CompiledMessage = string | CompiledMessagePart[]; type Messages = Record | Record; type AllMessages = Record | Record; type EventCallback = (...args: any[]) => any; type Events = { change: () => void; missing: (event: MissingMessageEvent) => void; }; type DatePool = Date | string; type I18nProviderProps = I18nContextProps & configProps; type InulaNode = InulaElement | string | number | Iterable | InulaPortal | boolean | null | undefined; /** * 时间格式化 */ declare class DateTimeFormatter { private readonly locales; private readonly formatOptions; private readonly cache?; private readonly valueKey?; constructor(locales: Locales, formatOptions?: Intl.DateTimeFormatOptions, cache?: I18nCache, valueKey?: string); dateTimeFormat(value: DatePool, formatOptions?: Intl.DateTimeFormatOptions): string; } /** * 数字格式化 */ declare class NumberFormatter { private readonly locales; private readonly formatOption?; private cache?; private readonly valueKey?; constructor(locales: Locales, formatOption?: Intl.NumberFormatOptions, cache?: I18nCache, valueKey?: string); numberFormat(value: number, formatOption?: Intl.NumberFormatOptions): string; } /** * 缓存机制 */ declare function creatI18nCache(): I18nCache; /** * FormattedMessage组件,接收一个消息键作为属性,并根据当前选择的语言环境,从对应的翻译资源中获取相应的消息文本,并可选地对文本进行格式化。 * @param props * @constructor */ declare function FormattedMessage(props: FormattedMessageProps): any; /** * 用于为应用程序提供国际化的格式化功能,管理程序中的语言文本信息和本地化资源信息 * @param props * @constructor */ declare const I18nProvider: (props: I18nProviderProps) => JSX.Element; declare const I18nContext: any; declare const InjectProvider: any; /** * 用于实现国际化的高阶组件,将国际化功能注入到组件中,使组件能够使用国际化的本文格式化功能 * @param Component * @param options */ declare function injectI18n(Component: any, options?: InjectOptions): any; /** * useI18n hook,与 Inula 组件一起使用。 * 使用 useI18n 钩子函数可以更方便地在函数组件中进行国际化操作 */ declare function useIntl(): any; /** * createIntl hook函数,用于创建国际化i8n实例,以进行相关的数据操作 */ declare const createIntl: (config: configProps, cache?: I18nCache) => any; declare function createI18n(options: I18nOptions): any; declare const useI18n: (options?: UseI18nOptions) => any; declare global { interface Window { $i18n: VueI18n; } } declare const _default: { I18n: typeof I18n; createIntlCache: typeof creatI18nCache; createIntl: (config: configProps, cache?: I18nCache | undefined) => any; DateTimeFormatter: typeof DateTimeFormatter; NumberFormatter: typeof NumberFormatter; useIntl: typeof useIntl; FormattedMessage: typeof FormattedMessage; I18nContext: any; IntlProvider: (props: I18nProviderProps) => JSX.Element; injectIntl: typeof injectI18n; RawIntlProvider: any; VueI18n: typeof VueI18n; }; declare function defineMessages>(msgs: U): U; declare function defineMessage(msg: T): T; export { DateTimeFormatter, FormattedMessage, I18n, I18nProvider, I18nContext as IntlContext, I18nProvider as IntlProvider, NumberFormatter, InjectProvider as RawIntlProvider, createI18n, createIntl, creatI18nCache as createIntlCache, _default as default, defineMessage, defineMessages, injectI18n as injectIntl, useI18n, useIntl };