Entry

Typdefinition für Übersetzungs-Entries, die in Batch-Übersetzungsvorgängen verwendet werden

Übersicht

Entry bezeichnet ein Übersetzungsanfrage-Objekt für Batch-Übersetzungen mit translateMany.

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

Eigenschaften

EigenschaftTypBeschreibung
sourceContentQuellinhalt zum Übersetzen
targetLocale?stringZiel-Locale (fällt auf die targetLocale der Instanz zurück)
metadata?EntryMetadataOptionale Metadaten zur Anpassung der Übersetzung

Inhaltstyp

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;
};

Aktionstyp

type ActionType = 'standard' | 'fast' | string;
  • 'standard' - Übersetzungsmodell mit höherer Qualität
  • 'fast' - Übersetzungsmodell mit geringerer Latenz

Beispiele

Grundlegende Verwendung

import { Entry } from 'generaltranslation';

const entries: Entry[] = [
  {
    source: 'Hello, world!',
    targetLocale: 'es'
  },
  {
    source: 'Good morning',
    targetLocale: 'de',
    metadata: {
      context: 'Formal greeting',
      actionType: 'standard'
    }
  }
];

Mit 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);

Verwandte Typen

Wie ist dieser Leitfaden?

Entry