Entry
批量翻译操作中使用的翻译 Entry 类型定义
概述
Entry 表示用于批量翻译场景的翻译请求对象,配合 translateMany 使用。
type Entry = {
  source: Content;
  targetLocale?: string;
  metadata?: EntryMetadata;
};属性
| 属性 | 类型 | 描述 | 
|---|---|---|
| source | Content | 待翻译的源内容 | 
| targetLocale? | string | 目标 locale(若未指定则回退为实例的 targetLocale) | 
| metadata? | EntryMetadata | 自定义翻译的可选元数据 | 
内容类型
type Content = JsxChildren | I18nextMessage | IcuMessage | string;EntryMetadata
type EntryMetadata = {
  context?: string;
  id?: string;
  hash?: string;
  dataFormat?: DataFormat;
  sourceLocale?: string;
  actionType?: ActionType;
  timeout?: number;
  regionCode?: string;
  scriptCode?: string;
};操作类型
type ActionType = 'standard' | 'fast' | string;- 'standard'- 高质量翻译模型
- 'fast'- 低延迟翻译模型
示例
基本用法
import { Entry } from 'generaltranslation';
const entries: Entry[] = [
  {
    source: '你好,世界!',
    targetLocale: 'es'
  },
  {
    source: '早上好',
    targetLocale: 'de',
    metadata: {
      context: '正式问候语',
      actionType: 'standard'
    }
  }
];使用 translateMany()
import { GT } from 'generaltranslation';
const gt = new GT({
  apiKey: 'your-api-key',
  sourceLocale: 'en'
});
const entries: Entry[] = [
  { source: 'Home', targetLocale: 'es' },
  { source: 'About', targetLocale: 'es' }
];
const results = await gt.translateMany(entries);相关类型
- EntryMetadata- 元数据选项
- TranslateManyResult- 批量翻译结果
这份指南怎么样?

