import { AllLocaleConfig, AllMessages, Locale, Locales, Error, DatePool, SelectPool, RawToken, InulaNode } from './types'; import I18n from '../core/I18n'; import Lexer from '../parser/Lexer'; import { InulaElement, Key } from 'openinula'; import VueI18n from '../vueI18n-adapter/src/VueI18n'; export interface FormattedMessageProps extends MessageDescriptor { values?: Record; tagName?: string; children?(nodes: any[]): any; } export interface MessageDescriptor extends MessageOptions { id: string; defaultMessage?: string; defaultValues?: Record; } export interface MessageOptions { comment?: string; messages?: string; context?: string; formatOptions?: FormatOptions; } export interface I18nCache { dateTimeFormat: Record; numberFormat: Record; plurals: Record; select: Record; octothorpe: Record; } export interface RichText { components?: { [key: string]: InulaNode; }; } export interface InulaPortal extends InulaElement { key: Key | null; children: InulaNode; } export type I18nProps = RichText & { locale?: Locale; locales?: Locales; messages?: AllMessages; defaultLocale?: string; timeZone?: string; localeConfig?: AllLocaleConfig; cache?: I18nCache; onError?: Error; }; export interface FormatOptions { dateTimeFormat?: Intl.DateTimeFormatOptions; numberFormat?: Intl.NumberFormatOptions; plurals?: Intl.PluralRulesOptions; } export interface InjectOptions { isUsingForwardRef?: boolean; ensureContext?: boolean; } export interface I18nContextProps { i18n?: I18n | VueI18n; } export type configProps = I18nProps & { RenderOnLocaleChange?: boolean; children?: any; onWarn?: Error; }; export interface IntlMessageFormat { plural: (value: number, { offset, ...rules }: { [x: string]: any; offset?: number | undefined; }) => (ctx: any) => any[]; selectordinal: (value: number, { offset, ...rules }: { [x: string]: any; offset?: number | undefined; }) => (ctx: any) => any[]; select: (value: SelectPool, formatRules: any) => any; numberFormat: (value: number, formatOption: any) => string; /** * eg: { year: 'numeric', month: 'long', day: 'numeric' } 是一个用于指定DateTimeFormatter如何将日期对象转换为字符串的参数。 * \year: 'numeric' 表示年份的表示方式是数字形式(比如2023)。 * month: 'long' 表示月份的表示方式是全名(比如January)。 * day: 'numeric' 表示日期的表示方式是数字形式(比如1号)。 * @param value * @param formatOption { year: 'numeric', month: 'long', day: 'numeric' } */ dateTimeFormat: (value: DatePool, formatOption: any) => string; undefined: (value: any) => any; } export interface MissingMessageEvent { locale: Locale; id: string; context?: string; } export interface LexerInterface { reset: (data?: string, info?: Record) => Lexer; next: () => RawToken | undefined; [Symbol.iterator](): Iterator; } export interface TokenContext { offset: number; line: number; col: number; text: string; lineNum: number; } export interface Content { type: 'content'; value: string; ctx: TokenContext; } export interface PlainArg { type: 'argument'; arg: string; ctx: TokenContext; } export interface Octothorpe { type: 'octothorpe'; ctx: TokenContext; } export interface FunctionArg { type: 'function'; arg: string; key: string; param?: Array; ctx: TokenContext; } export interface SelectCase { key: string; tokens: Array; ctx: TokenContext; } export interface Select { type: 'plural' | 'select' | 'selectordinal'; arg: string; cases: SelectCase[]; offset?: number; ctx: TokenContext; } export interface InjectedIntl { formatDate(value: DatePool, options?: Intl.DateTimeFormatOptions): string; formatTime(value: DatePool, options?: Intl.DateTimeFormatOptions): string; formatNumber(value: number, options?: Intl.NumberFormatOptions): string; formatMessage(messageDescriptor: MessageDescriptor, values?: Record, options?: MessageOptions): string | any[]; }