Skip to main content
Glama
mmntm

Weblate MCP Server

by mmntm

findTranslationsForKey

Locate all translations for a specific key across all components and languages in a Weblate project to manage translation consistency.

Instructions

Find all translations for a specific key across all components and languages in a project

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectSlugYesThe slug of the project
keyYesThe exact translation key to find

Implementation Reference

  • The handler function decorated with @Tool decorator. Handles input validation via Zod schema, calls the WeblateApiService to find translations, groups results by component/language, formats the output, and handles errors.
    @Tool({ name: 'findTranslationsForKey', description: 'Find all translations for a specific key across all components and languages in a project', parameters: z.object({ projectSlug: z.string().describe('The slug of the project'), key: z.string().describe('The exact translation key to find'), }), }) async findTranslationsForKey({ projectSlug, key, }: { projectSlug: string; key: string; }) { try { const results = await this.weblateApiService.findTranslationsForKey( projectSlug, key, ); if (results.length === 0) { return { content: [ { type: 'text', text: `No translations found for key "${key}" in project "${projectSlug}"`, }, ], }; } // Group by component and language for better readability const groupedResults = results.reduce((acc: Record<string, Unit[]>, translation) => { const component = translation.web_url?.split('/')[4] || 'unknown'; const language = translation.web_url?.split('/')[6] || 'unknown'; const groupKey = `${component}/${language}`; if (!acc[groupKey]) { acc[groupKey] = []; } acc[groupKey].push(translation); return acc; }, {}); const formattedResults = Object.entries(groupedResults) .map(([groupKey, translations]) => { const [component, language] = groupKey.split('/'); const translationList = translations.map(this.formatTranslationResult).join('\n'); return `**${component} (${language}):**\n${translationList}`; }) .join('\n\n'); return { content: [ { type: 'text', text: `Found ${results.length} translations for key "${key}" in project "${projectSlug}":\n\n${formattedResults}`, }, ], }; } catch (error) { this.logger.error( `Failed to find translations for key "${key}" in ${projectSlug}`, error, ); return { content: [ { type: 'text', text: `Error finding translations for key "${key}" in project "${projectSlug}": ${error.message}`, }, ], isError: true, }; } }
  • Zod schema defining the input parameters for the tool: projectSlug and key.
    parameters: z.object({ projectSlug: z.string().describe('The slug of the project'), key: z.string().describe('The exact translation key to find'), }),
  • Registration of the WeblateTranslationsTool class in the NestJS AppModule providers array, making the tool available to the MCP server.
    providers: [ WeblateClientService, WeblateProjectsService, WeblateComponentsService, WeblateLanguagesService, WeblateTranslationsService, WeblateChangesService, WeblateApiService, WeblateStatisticsService, WeblateProjectsTool, WeblateComponentsTool, WeblateLanguagesTool, WeblateTranslationsTool, WeblateChangesTool, WeblateStatisticsTool, ], })
  • Core helper function that implements the search logic by querying Weblate units API with context:"key" filter to find all translations for the specific key.
    async findTranslationsForKey( projectSlug: string, key: string, componentSlug?: string, ): Promise<Unit[]> { try { const searchResult = await this.searchTranslations( projectSlug, componentSlug, undefined, `context:"${key}"`, ); return searchResult.results; } catch (error) { this.logger.error( `Failed to find translations for key "${key}" in project ${projectSlug}`, error, ); throw new Error( `Failed to find translations for key: ${error.message}`, ); } }
  • Intermediate helper in WeblateApiService that delegates the findTranslationsForKey call to the underlying translations service.
    async findTranslationsForKey( projectSlug: string, key: string, componentSlug?: string, ): Promise<Unit[]> { return this.translationsService.findTranslationsForKey( projectSlug, key, componentSlug, ); }

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