Types

EntryMetadata

用于在 Entry 对象中自定义翻译行为的元数据类型定义

概览

EntryMetadata 为批量翻译操作中的 Entry 对象提供可选配置。

type EntryMetadata = {
  context?: string;
  id?: string;
  hash?: string;
  dataFormat?: DataFormat;
  sourceLocale?: string;
  actionType?: ActionType;
  timeout?: number;
  regionCode?: string;
  scriptCode?: string;
};

属性

属性类型描述
context?string提供给译者的上下文
id?string唯一标识符
hash?string用于缓存的内容哈希
dataFormat?DataFormat格式规范
sourceLocale?string源语言(sourceLocale)覆盖
actionType?ActionType翻译模型偏好设置
timeout?number请求超时时间(毫秒)
regionCode?stringISO 地区代码
scriptCode?stringISO 文字脚本代码

相关类型

type DataFormat = 'JSX' | 'ICU' | 'I18NEXT';
type ActionType = 'standard' | 'fast' | string;

示例

基本用法

import { Entry, EntryMetadata } from 'generaltranslation';

const metadata: EntryMetadata = {
  context: '按钮文字',
  actionType: 'fast'
};

const entry: Entry = {
  source: '保存',
  targetLocale: 'es',
  metadata
};

使用 ICU 格式

const icuEntry: Entry = {
  source: '{count, plural, other {{count} 个项目}}',
  targetLocale: 'es',
  metadata: {
    dataFormat: 'ICU',
    context: '项目数量'
  }
};

相关类型

  • Entry - 使用该元数据的父类型
  • ActionType - 翻译模型的选项

本指南如何?