translateMany
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 optimised for batch processing and delivers better performance than making multiple individual translate calls.
const gt = new GT({
apiKey: 'your-api-key',
projectId: 'your-project-id'
});
const result = await gt.translateMany([
{ source: 'Hello, world!' },
{ source: 'Welcome to our app' },
{ source: 'Click here to continue' }
], { targetLocale: 'es' });Reference
Parameters
Prop
Type
Parameter descriptions
| Parameter | Description |
|---|---|
sources | Array of Entry objects containing source content and optional per-item metadata |
globalMetadata | Global metadata applied to all entries, including the required targetLocale |
Entry Object Structure
Each entry in the sources array may contain:
interface Entry {
source: Content; // The content to translate
targetLocale?: string; // Override global target locale
context?: string; // Translation context for this entry
tags?: string[]; // Tags for categorisation
// ... other EntryMetadata properties
}Returns
Promise<TranslateManyResult>The result includes translated entries and any error information:
interface TranslateManyResult {
translations: Array<TranslationResult | TranslationError>;
metadata: {
totalRequests: number;
successCount: number;
errorCount: number;
processingTime: number;
};
}Behaviour
Global vs Per-Item Metadata
- Global metadata applies to all entries by default
- Per-item metadata overrides global settings for specific entries
- The target locale can be overridden per entry
Error handling strategy
- Individual translation failures don’t halt the entire batch
- Each result indicates success or failure independently
- Partial-success scenarios are fully supported
Locale resolution
- The global target locale is used by default for all entries
- Per-entry target locales override the global setting
- All locales are resolved via custom mapping if configured
Examples
const menuItems = await gt.translateMany([
{ source: 'Home' },
{ source: 'About' },
{ source: 'Products' },
{ source: 'Contact' }
], {
targetLocale: 'fr',
context: 'Navigation menu items'
});
menuItems.translations.forEach((result, index) => {
if ('translation' in result) {
console.log(`Item ${index}: ${result.translation}`);
} else {
console.error(`Item ${index} failed: ${result.error}`);
}
});Notes
- Translates multiple items in a single API request
- A failure in one entry doesn’t affect the others
- Results keep the same order as the input entries
- Global metadata is merged with per-entry metadata (per-entry takes precedence)
Next steps
- Learn about single translations with translate
- Explore Entry and EntryMetadata types
- Understand TranslateManyResult structure
How is this guide?