Skip to main content
Glama
mmntm

Weblate MCP Server

by mmntm

writeTranslation

Update or write translation values for specific keys in Weblate translation projects to manage multilingual content.

Instructions

Update or write a translation value for a specific key

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectSlugYesThe slug of the project
componentSlugYesThe slug of the component
languageCodeYesThe language code (e.g., en, es, fr)
keyYesThe translation key to update
valueYesThe new translation value
markAsApprovedNoWhether to mark as approved (default: false)

Implementation Reference

  • The MCP tool handler function that executes the writeTranslation logic. It calls the WeblateApiService, handles success/error responses, and formats the output using formatTranslationResult.
    async writeTranslation({ projectSlug, componentSlug, languageCode, key, value, markAsApproved = false, }: { projectSlug: string; componentSlug: string; languageCode: string; key: string; value: string; markAsApproved?: boolean; }) { try { const updatedUnit = await this.weblateApiService.writeTranslation( projectSlug, componentSlug, languageCode, key, value, markAsApproved, ); return { content: [ { type: 'text', text: updatedUnit ? `Successfully updated translation for key "${key}"\n\n${this.formatTranslationResult(updatedUnit)}` : `Failed to update translation for key "${key}"`, }, ], }; } catch (error) { this.logger.error(`Failed to write translation for key ${key}`, error); return { content: [ { type: 'text', text: `Error writing translation for key "${key}": ${error.message}`, }, ], isError: true, }; } }
  • Tool metadata including name, description, and Zod input schema for validation.
    @Tool({ name: 'writeTranslation', description: 'Update or write a translation value for a specific key', 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)'), 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), }), })
  • NestJS module providers list that registers the WeblateTranslationsTool containing the writeTranslation tool with the MCP framework.
    providers: [ WeblateClientService, WeblateProjectsService, WeblateComponentsService, WeblateLanguagesService, WeblateTranslationsService, WeblateChangesService, WeblateApiService, WeblateStatisticsService, WeblateProjectsTool, WeblateComponentsTool, WeblateLanguagesTool, WeblateTranslationsTool, WeblateChangesTool, WeblateStatisticsTool, ], })
  • Helper method in WeblateApiService that proxies the writeTranslation call to the underlying translations service.
    async writeTranslation( projectSlug: string, componentSlug: string, languageCode: string, key: string, value: string, markAsApproved: boolean = false, ): Promise<Unit | null> { return this.translationsService.writeTranslation( projectSlug, componentSlug, languageCode, key, value, markAsApproved, ); }
  • Core service implementation that locates the translation unit by key, handles plural forms parsing, and performs the actual Weblate API update using unitsPartialUpdate.
    async writeTranslation( projectSlug: string, componentSlug: string, languageCode: string, key: string, value: string, markAsApproved: boolean = false, ): Promise<Unit | null> { try { // First, find the translation unit by key const unit = await this.getTranslationByKey( projectSlug, componentSlug, languageCode, key, ); if (!unit || !unit.id) { throw new Error(`Translation unit not found for key "${key}"`); } const client = this.weblateClientService.getClient(); // Parse plural forms correctly for the target field using language-specific rules const targetArray = this.parsePluralForms(value, unit.source, languageCode); // Update the translation using the units API const response = await unitsPartialUpdate({ client, path: { id: unit.id.toString() }, body: { target: targetArray, // Properly parsed plural forms state: markAsApproved ? 30 : 20, // 30 = approved, 20 = translated }, }); return response.data as Unit; } catch (error) { this.logger.error(`Failed to write translation for key ${key}`, error); throw new Error( `Failed to write translation for key ${key}: ${error.message}`, ); } }

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