Entry

一括翻訳処理で使用する翻訳エントリの型定義

概要

Entry は、translateMany を用いた一括翻訳処理における翻訳リクエストオブジェクトを表します。

type Entry = {
  source: Content;
  targetLocale?: string;
  metadata?: EntryMetadata;
};

プロパティ

プロパティ説明
sourceContent翻訳するソースコンテンツ
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;
};

ActionType

type ActionType = 'standard' | 'fast' | string;
  • 'standard' - 高品質な翻訳モデル
  • 'fast' - 低レイテンシーの翻訳モデル

基本的な使用方法

import { Entry } from 'generaltranslation';

const entries: Entry[] = [
  {
    source: 'Hello, world!',
    targetLocale: 'es'
  },
  {
    source: 'Good morning',
    targetLocale: 'de',
    metadata: {
      context: 'Formal greeting',
      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);

関連する型

このガイドはいかがですか?