Skip to main content
Glama
mmntm

Weblate MCP Server

by mmntm

getTranslationForKey

Retrieve translation text for a specific key in a Weblate project component and language.

Instructions

Get translation value for a specific key in a project

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 look up

Implementation Reference

  • The handler function that implements the core logic of the getTranslationForKey tool. It calls the WeblateApiService to retrieve the translation and handles formatting and error responses.
    async getTranslationForKey({ projectSlug, componentSlug, languageCode, key, }: { projectSlug: string; componentSlug: string; languageCode: string; key: string; }) { try { const translation = await this.weblateApiService.getTranslationByKey( projectSlug, componentSlug, languageCode, key, ); if (!translation) { return { content: [ { type: 'text', text: `Translation not found for key "${key}" in ${projectSlug}/${componentSlug}/${languageCode}`, }, ], }; } return { content: [ { type: 'text', text: this.formatTranslationResult(translation), }, ], }; } catch (error) { this.logger.error(`Failed to get translation for key ${key}`, error); return { content: [ { type: 'text', text: `Error getting translation for key "${key}": ${error.message}`, }, ], isError: true, }; } }
  • Zod schema defining the input parameters for the getTranslationForKey tool.
    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 look up'), }),
  • The @Tool decorator that registers the getTranslationForKey tool with MCP, including name, description, and parameter schema.
    @Tool({ name: 'getTranslationForKey', description: 'Get translation value for a specific key in a project', 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 look up'), }), })
  • Helper method used by the handler to format the translation result for display.
    private formatTranslationResult(translation: Unit): string { const status = translation.approved ? 'βœ… Approved' : translation.translated ? 'πŸ“ Translated' : '❌ Untranslated'; const sourceText = translation.source && Array.isArray(translation.source) ? translation.source.join('') : (translation.source || '(empty)'); const targetText = translation.target && Array.isArray(translation.target) ? translation.target.join('') : (translation.target || '(empty)'); return `**Key:** ${translation.context} **Source:** ${sourceText} **Target:** ${targetText} **Status:** ${status} **Context:** ${translation.context || '(none)'} **Note:** ${translation.note || '(none)'} **ID:** ${translation.id}`; }

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