import type { ComputedRef, InjectionKey, MaybeRef, Ref } from 'vue' import type { Awaitable, Union2Intersection } from './typed.js' /** 语言对象类型 */ export interface Language { zhCN: 'zh-CN' enUS: 'en-US' } /** * 语言对象 * @reactively */ export declare const lang: Language /** 语言区域 */ export type Locale = Language[keyof Language] | (string & {}) /** Options for {@link plugin} */ export interface I18nPluginOptions { /** 语言区域 */ locale: MaybeRef /** * 默认语言区域 * * @defaultValue Locale.zhCN */ defaultLocale?: Locale /** * 切换语言时是否响应式 * 如果切换界面语言时刷新页面,请设置为 false,可以减少 vue 的响应式消耗 * * @defaultValue true */ reactive?: boolean } /** * 国际化插件 * - vue-plugin * * @param app - 应用 * @param options - 选项 */ export declare function plugin( app: { provide | string | number>(key: K, value: K extends InjectionKey ? V : T): void }, options: I18nPluginOptions, ): void export default plugin /** 国际化注入键 */ export declare const I18N_INJECTION: InjectionKey< Readonly<{ /** 语言区域 */ locale: Ref /** * 默认语言区域 * * @defaultValue Locale.zhCN */ defaultLocale: Locale /** 切换语言时是否响应式 */ reactive: boolean }> > /** 解析国际化资源 */ export type ParseMessage = Union2Intersection<_MapKey> /** 国际化实例 */ export interface I18nInstance { /** 语言区域 */ locale: Ref /** * 翻译 * @param key - 键名 * @param parameter - 参数 * @param options - 选项 * @returns 资源 */ t string ? P : Record>( this: void, key: Key, parameter?: Parameter, options?: { fallback?: string | null locale?: Locale } ): string /** * 翻译 * @param key - 键名 * @param parameter - 参数 * @param locale - 语言区域 * @returns 资源 */ t string ? P : Record>( this: void, key: Key, parameter?: Parameter, locale?: Locale ): string /** * 翻译 * @param key - 键名 * @param parameter - 参数 * @param options - 选项 * @returns 资源 */ $t string ? P : Record>( this: void, key: Key, parameter?: Parameter, options?: { fallback?: string | null locale?: Locale } ): ComputedRef /** * 翻译 * @param key - 键名 * @param parameter - 参数 * @param locale - 语言区域 * @returns 资源 */ $t string ? P : Record>( this: void, key: Key, parameter?: Parameter, locale?: Locale ): ComputedRef /** * 加载语言资源 */ load: () => Promise } /** * 国际化 composable * @param locale - 语言区域 * @param fallback - 资源回退函数 * @returns 国际化实例 */ export type I18nComposable = ( locale?: MaybeRef, fallback?: (key: string, parameter: Record, locale: Locale) => string, ) => I18nInstance /** * 国际化资源加载器 * @param locale - 语言区域 * @returns 国际化资源 */ export type DefineI18nLoader = (locale: Locale) => Awaitable /** * options for {@link defineI18n} */ export interface DefineI18nOptions { /** * 切换语言时是否响应式 * 如果切换界面语言时刷新页面,请设置为 false,可以减少 vue 的响应式消耗 * * @defaultValue 跟随 {@link I18nPluginOptions.reactive} */ reactive?: boolean /** * 资源回退函数 * - 当资源加载失败时,使用该函数返回默认值 * @param key - 键名 * @param parameter - 参数 * @param locale - 语言区域 * @returns 资源 */ fallback?: (key: string, parameter: unknown, locale: Locale) => string } /** * 定义国际化 composable * * @param loader - 国际化资源加载器 * @param options - 选项 * @returns 国际化 composable */ export declare function defineI18n( loader: DefineI18nLoader, options?: DefineI18nOptions, ): I18nComposable> type _GetString = (...p: any[]) => string type _MapItem< M, K extends (keyof M) & string, Pre extends string | false, P extends string = Pre extends string ? `${Pre}.${K}` : `${K}`, > = M[K] extends string | _GetString ? { [k in P as `${P}`]: M[K] } : _MapKey type _MapKey = K extends infer F1 extends (keyof M) & string ? _MapItem : never export function mapMessage( locale: string, msg: Message, prefix?: Prefix, ): ParseMessage