Skip to main content
Glama
mmntm

Weblate MCP Server

by mmntm

bulkWriteTranslations

Update multiple translations simultaneously in Weblate projects to manage batch operations efficiently. Specify project, component, language, and translation values to process updates.

Instructions

Update multiple translations in batch for efficient bulk operations

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectSlugYesThe slug of the project
componentSlugYesThe slug of the component
languageCodeYesThe language code (e.g., en, es, fr)
translationsYesArray of translations to update

Implementation Reference

  • Primary MCP tool handler for 'bulkWriteTranslations', including inline Zod schema for parameters, registration via @Tool decorator, and logic to call service and format response with success/failure summary.
    @Tool({ name: 'bulkWriteTranslations', description: 'Update multiple translations in batch for efficient bulk operations', parameters: z.object({ projectSlug: z.string().describe('The slug of the project'), componentSlug: z.string().describe('The slug of the component'), languageCode: z.string().describe('The language code (e.g., en, es, fr)'), translations: z.array(z.object({ key: z.string().describe('The translation key to update'), value: z.string().describe('The new translation value'), markAsApproved: z.boolean().optional().describe('Whether to mark as approved (default: false)').default(false), })).describe('Array of translations to update'), }), }) async bulkWriteTranslations({ projectSlug, componentSlug, languageCode, translations, }: { projectSlug: string; componentSlug: string; languageCode: string; translations: Array<{ key: string; value: string; markAsApproved?: boolean; }>; }) { try { const result = await this.weblateApiService.bulkWriteTranslations( projectSlug, componentSlug, languageCode, translations, ); let resultText = `Bulk translation update completed for ${projectSlug}/${componentSlug}/${languageCode}\n\n`; resultText += `πŸ“Š **Summary:**\n`; resultText += `- Total: ${result.summary.total}\n`; resultText += `- βœ… Successful: ${result.summary.successful}\n`; resultText += `- ❌ Failed: ${result.summary.failed}\n\n`; if (result.successful.length > 0) { resultText += `βœ… **Successfully Updated (${result.successful.length}):**\n`; result.successful.slice(0, 10).forEach(({ key }) => { resultText += `- ${key}\n`; }); if (result.successful.length > 10) { resultText += `... and ${result.successful.length - 10} more\n`; } resultText += '\n'; } if (result.failed.length > 0) { resultText += `❌ **Failed Updates (${result.failed.length}):**\n`; result.failed.slice(0, 5).forEach(({ key, error }) => { resultText += `- ${key}: ${error}\n`; }); if (result.failed.length > 5) { resultText += `... and ${result.failed.length - 5} more failures\n`; } } return { content: [ { type: 'text', text: resultText, }, ], }; } catch (error) { this.logger.error(`Failed to bulk write translations`, error); return { content: [ { type: 'text', text: `Error during bulk translation update: ${error.message}`, }, ], isError: true, }; } }
  • Helper method in WeblateApiService that delegates bulkWriteTranslations to the underlying translationsService.
    async bulkWriteTranslations( projectSlug: string, componentSlug: string, languageCode: string, translations: Array<{ key: string; value: string; markAsApproved?: boolean; }>, ): Promise<{ successful: Array<{ key: string; unit: Unit }>; failed: Array<{ key: string; error: string }>; summary: { total: number; successful: number; failed: number; }; }> { return this.translationsService.bulkWriteTranslations( projectSlug, componentSlug, languageCode, translations, ); }
  • Core implementation of bulkWriteTranslations in WeblateTranslationsService, handling batched parallel updates via writeTranslation with concurrency control, collecting success/failure stats.
    /** * Bulk update multiple translations efficiently */ async bulkWriteTranslations( projectSlug: string, componentSlug: string, languageCode: string, translations: Array<{ key: string; value: string; markAsApproved?: boolean; }>, ): Promise<{ successful: Array<{ key: string; unit: Unit }>; failed: Array<{ key: string; error: string }>; summary: { total: number; successful: number; failed: number; }; }> { const successful: Array<{ key: string; unit: Unit }> = []; const failed: Array<{ key: string; error: string }> = []; this.logger.log(`Starting bulk update of ${translations.length} translations for ${projectSlug}/${componentSlug}/${languageCode}`); // Process translations in parallel (but with some concurrency control) const concurrencyLimit = 5; // Limit concurrent requests to avoid overwhelming the API const chunks = []; for (let i = 0; i < translations.length; i += concurrencyLimit) { chunks.push(translations.slice(i, i + concurrencyLimit)); } for (const chunk of chunks) { const promises = chunk.map(async ({ key, value, markAsApproved = false }) => { try { const updatedUnit = await this.writeTranslation( projectSlug, componentSlug, languageCode, key, value, markAsApproved, ); if (updatedUnit) { successful.push({ key, unit: updatedUnit }); this.logger.debug(`Successfully updated translation for key: ${key}`); } else { failed.push({ key, error: 'No unit returned from update' }); } } catch (error) { failed.push({ key, error: error.message }); this.logger.warn(`Failed to update translation for key ${key}: ${error.message}`); } }); // Wait for current chunk to complete before processing next chunk await Promise.allSettled(promises); } const summary = { total: translations.length, successful: successful.length, failed: failed.length, }; this.logger.log(`Bulk update completed: ${summary.successful}/${summary.total} successful, ${summary.failed} failed`); return { successful, failed, summary, }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mmntm/weblate-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server