# generaltranslation: General Translation Core SDK: translateMany URL: https://generaltranslation.com/en-US/docs/core/class/methods/translation/translate-many.mdx --- title: translateMany description: API reference for the GT translateMany method for batch translations --- ## Overview The `translateMany` method efficiently translates multiple content items in a single API request. It's optimized for batch processing and provides better performance than multiple individual `translate` calls. ```typescript const gt = new GT({ apiKey: 'your-api-key', projectId: 'your-project-id' }); const results = await gt.translateMany( ['Hello, world!', 'Welcome to our app', 'Click here to continue'], 'es' ); ``` --- ## Reference ### Overload 1: Array of entries ```typescript translateMany( sources: TranslateManyEntry[], options: string | TranslateOptions, timeout?: number ): Promise ``` Returns a `TranslateManyResult` (an array of `TranslationResult` objects) in the same order as the input. ### Overload 2: Record of entries ```typescript translateMany( sources: Record, options: string | TranslateOptions, timeout?: number ): Promise> ``` When given a record keyed by hash, returns a record keyed by the same hashes. ### Parameters ', description: 'Array or record of entries to translate.', optional: false, }, "options": { type: 'string | TranslateOptions', description: 'Target locale string (shorthand) or an options object.', optional: false, }, "timeout?": { type: 'number', description: 'Optional request timeout in milliseconds.', optional: true, } }} /> ### TranslateManyEntry Each entry can be a plain string or an object with source content and optional metadata: ```typescript type TranslateManyEntry = string | { source: Content; metadata?: EntryMetadata }; ``` ### TranslateOptions ```typescript type TranslateOptions = { targetLocale: string; sourceLocale?: string; modelProvider?: string; }; ``` ### Parameters description | Parameter | Description | |-----------|-------------| | `sources` | Array or record of `TranslateManyEntry` items. Each can be a plain string or an object with `source` and optional `metadata`. | | `options` | A target locale string (e.g., `'es'`) or an options object with `targetLocale`, optional `sourceLocale`, and `modelProvider`. | | `timeout` | Optional request timeout in milliseconds. | ### Returns - **Array input** → `Promise` (`TranslationResult[]`), same order as input - **Record input** → `Promise>`, keyed by the same hashes --- ## Behavior ### Array vs Record - **Array**: Entries are hashed internally; results are returned in input order. - **Record**: Keys are treated as hashes; the response is a record with the same keys. ### Error handling strategy - Individual translation failures don't stop the entire batch - Each result indicates success or failure independently - Partial success scenarios are fully supported ### Options shorthand You can pass a string as the `options` parameter as a shorthand for `{ targetLocale: string }`: ```typescript // These are equivalent: await gt.translateMany(['Hello', 'Goodbye'], 'es'); await gt.translateMany(['Hello', 'Goodbye'], { targetLocale: 'es' }); ``` --- ## Examples ### Array of strings ```typescript const results = await gt.translateMany( ['Home', 'About', 'Products', 'Contact'], 'fr' ); results.forEach((result, index) => { if (result.success) { console.log(`Item ${index}: ${result.translation}`); } else { console.error(`Item ${index} failed: ${result.error}`); } }); ``` ### Array with metadata ```typescript const results = await gt.translateMany( [ { source: 'Hello, world!', metadata: { dataFormat: 'ICU' } }, { source: 'Goodbye, world!' } ], { targetLocale: 'es' } ); ``` ### Record (keyed by hash) ```typescript const results = await gt.translateMany( { 'greeting-hash': 'Hello, world!', 'farewell-hash': 'Goodbye, world!' }, 'es' ); console.log(results['greeting-hash'].translation); ``` --- ## Notes - Translates multiple items in a single API request - Translation failures in one entry don't affect others - Results maintain the same order as input entries (array) or same keys (record) ## Next steps - Learn about single translations with [translate](/docs/core/class/methods/translation/translate) - Explore [TranslateManyEntry type](/docs/core/types/Entry) - Understand [TranslateManyResult structure](/docs/core/types/translate-many-result)