findTranslationsForKey
Locate all translations for a specific key across languages and components in a project on Weblate MCP Server. Simplify translation tracking and management.
Instructions
Find all translations for a specific key across all components and languages in a project
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | The exact translation key to find | |
| projectSlug | Yes | The slug of the project |
Implementation Reference
- src/tools/translations.tool.ts:302-378 (handler)The primary handler for the 'findTranslationsForKey' MCP tool. It defines the tool schema with Zod, handles input validation, calls the Weblate API service to retrieve matching translations, groups results by component and language, formats them for display, and returns structured content or error responses.@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 (string) and key (string).parameters: z.object({ projectSlug: z.string().describe('The slug of the project'), key: z.string().describe('The exact translation key to find'), }),
- src/app.module.ts:45-45 (registration)Tool listed in the MCP server instructions/descriptions.- findTranslationsForKey: Find all translations for a specific key
- src/app.module.ts:77-77 (registration)The tool class is registered as a provider in the NestJS AppModule.WeblateTranslationsTool,
- Core helper method in WeblateTranslationsService that searches for translation units by exact context/key match across the project (or specific component), using Weblate's search API with context filter.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}`, ); } }