import { default as React, ReactNode } from 'react'; import { Locale, LocaleMessages } from '../locales'; /** * 插值参数类型 */ export type InterpolationParams = Record; /** * 翻译函数类型 * @param key 翻译键,支持点分隔的嵌套键 * @param params 插值参数,用于替换翻译文本中的 {key} 占位符 * @returns 翻译后的文本 * * @example * ```typescript * // 基础用法 * t('toolbar.bold') // -> "粗体" * * // 插值用法 * t('upload.maxSize', { size: '10MB' }) // -> "文件大小不能超过 10MB" * ``` */ export type TFunction = (key: string, params?: InterpolationParams) => string; interface I18nContextType { /** 当前语言 */ locale: Locale; /** 当前语言的所有翻译消息 */ messages: LocaleMessages; /** 切换语言 */ setLocale: (locale: Locale) => void; /** 翻译函数 */ t: TFunction; /** 检查翻译键是否存在 */ hasKey: (key: string) => boolean; } export interface I18nProviderProps { /** 子组件 */ children: ReactNode; /** 初始语言,默认 'zh-CN' */ locale?: Locale; /** 语言变化回调 */ onLocaleChange?: (locale: Locale) => void; /** * 缺失键时的回调 * 可用于收集缺失的翻译键进行上报 */ onMissingKey?: (key: string, locale: Locale) => void; /** * 是否在开发模式下显示缺失键警告 * @default true */ warnOnMissingKey?: boolean; } /** * 国际化提供者组件 * * @example * ```tsx * // 基础用法 * * * * * // 带回调 * console.log('Changed to:', locale)} * onMissingKey={(key) => console.warn('Missing:', key)} * > * * * ``` */ export declare const I18nProvider: React.FC; /** * 获取国际化上下文的 Hook * * @example * ```tsx * function MyComponent() { * const { t, locale, setLocale } = useI18n(); * * return ( *
*

{t('toolbar.bold')}

*

{t('upload.maxSize', { size: '10MB' })}

* *
* ); * } * ``` */ export declare const useI18n: () => I18nContextType; /** * 创建命名空间翻译函数 * 用于在组件中简化翻译键的使用 * * @param namespace 命名空间前缀 * @returns 带命名空间的翻译函数 * * @example * ```tsx * function ToolbarComponent() { * const { t } = useI18n(); * const tt = createNamespacedT(t, 'toolbar'); * * return ( *
* // 等价于 t('toolbar.bold') * // 等价于 t('toolbar.italic') *
* ); * } * ``` */ export declare function createNamespacedT(t: TFunction, namespace: string): TFunction; export {};