TranslationBatch

@ai-i18n/vite 导入:

import type { TranslationBatch } from '@ai-i18n/vite';

定义

interface TranslationBatch {
  batchId?: string;
  logging?: TranslationLogging;
  locales: readonly string[];
  messages: readonly TranslationMessage[];
}

字段

字段类型必填作用
batchIdstring本批诊断 ID;由 Vite 调度器生成。
loggingTranslationLogging关闭日志,或给出已解析日志目录。
localesreadonly string[]本批所有消息共同缺失的语言。
messagesreadonly TranslationMessage[]按固定下标排列的消息。

Vite 按缺失 locale 集合分组,再根据 AiI18nProviderOptions.batchLength 切分批次。 batchId 只用于把调度、模型日志、状态应用和持久化事件关联起来,不发送给模型,也不参与 message ID、缓存键或 Translation Memory 文件格式。直接调用 Translator 时,Translator 可以为缺失的 batchId 生成本地诊断 ID。

Vite 根据 provider.logging 传入 logging。启用时,字符串是基于 Vite root 解析后的绝对目录; 关闭时为 false。自定义 Translator 可以忽略该可选字段;官方 OpenAI Provider 在值为 false 时 仍执行翻译,但不创建或追加日志。实现 reportBatchEvent 的 Translator 仍会收到生命周期事件。