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}`,
        );
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It states 'Update or write' implying a mutation, but doesn't disclose behavioral traits like required permissions, whether it overwrites existing values, error handling, or rate limits. This leaves significant gaps for safe and effective use.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's function without unnecessary words. It's appropriately sized and front-loaded, making it easy to grasp quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with no annotations and no output schema, the description is incomplete. It lacks details on behavioral aspects like side effects, return values, or error conditions, which are crucial for an AI agent to use it correctly in context with its siblings.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all 6 parameters. The description adds no additional meaning beyond the schema, such as explaining relationships between parameters or usage examples. Baseline 3 is appropriate when schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Update or write') and resource ('translation value for a specific key'), making the purpose understandable. However, it doesn't explicitly differentiate from sibling tools like 'bulkWriteTranslations' or 'getTranslationForKey', which would require more specificity about scope or use cases.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'bulkWriteTranslations' for multiple updates and 'getTranslationForKey' for retrieval, there's no mention of when this single-update tool is preferred, nor any prerequisites or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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