/** * UI18N API签名自动检测与适配器 * * 自动识别用户提供的translateApi是单文本模式还是批量模式, * 并提供统一的批量翻译接口 * * 支持的API签名: * - 单文本:(text: string, targetLang: string, sourceLang?: string) => Promise * - 批量:(texts: string[], sourceLang: string, targetLang: string) => Promise */ export type SingleTextApi = (text: string, targetLang: string, sourceLang?: string) => Promise; export type BatchTextApi = (texts: string[], sourceLang: string, targetLang: string) => Promise; export type TranslateApiFunction = SingleTextApi | BatchTextApi; /** * API模式检测结果 */ export type ApiMode = 'single' | 'batch'; /** * API适配器类 - 自动检测并适配不同的API签名 */ export declare class TranslateApiAdapter { private mode; private translateApi; private explicitMode?; constructor(translateApi: Function, explicitMode?: ApiMode); /** * 统一的批量翻译接口 * @param texts 要翻译的文本数组 * @param targetLang 目标语言 * @param sourceLang 源语言(默认'auto') * @returns 翻译结果数组 */ translate(texts: string[], targetLang: string, sourceLang?: string): Promise; /** * 检测API模式(优先级:显式指定 > 静态分析 > 运行时探测) */ private detectMode; /** * 静态分析函数签名 */ private detectFromSignature; /** * 运行时探测API签名 * 使用测试数据尝试调用,根据返回值判断模式 */ private detectAtRuntime; /** * 调用批量API */ private callBatchApi; /** * 标准化API返回格式 - 支持多种返回格式 * * 支持的格式: * 1. string[] 数组 - 直接返回 * 2. {text_0: "...", text_1: "..."} - 索引key的对象 * 3. {原文: "译文", ...} - 原文作为key的对象 * 4. {key0: "...", key1: "..."} - 自定义key的对象 * * @param result API返回的原始结果 * @param texts 原始文本数组(用于匹配顺序) * @returns 标准化后的string[]数组 */ private normalizeApiResponse; /** * 调用单文本API(逐个翻译) */ private callSingleApi; /** * 获取当前检测到的模式(用于调试) */ getMode(): ApiMode | null; } //# sourceMappingURL=api-adapter.d.ts.map