Generate Translation Previews
amerta / amerta/payload/fields/translate/actions/translateBulk / generateTranslationPreviews
Function: generateTranslationPreviews()
generateTranslationPreviews(
collectionSlug,ids,targetLocale,sourceLocale?):Promise<{previews:any[];success:boolean; }>
Defined in: amerta/payload/fields/translate/actions/translateBulk.ts:24
Generates translation previews for specified documents in a collection. Batches documents by size limits to optimize API usage, translates specified fields, and returns previews organized by document with original and translated text.
Parameters
| Parameter | Type | Default value | Description |
| ------ | ------ | ------ | ------ |
| collectionSlug | string | undefined | The slug of the Payload collection to translate. |
| ids | string[] | undefined | Array of document IDs to translate. |
| targetLocale | string | undefined | The target language code (e.g., 'fr', 'de'). |
| sourceLocale | string | "en" | The source language code (default: 'en'). |
Returns
Promise<{ previews: any[]; success: boolean; }>
An object containing success status and array of preview objects with original and translated fields.
Example
const result = await generateTranslationPreviews('products', ['doc1', 'doc2'], 'fr');