getTranslationStatistics
Retrieve detailed statistics for a specific translation project, component, and language combination using the Weblate MCP Server. Analyze translation progress and accuracy efficiently.
Instructions
Get statistics for a specific translation (project/component/language combination)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| componentSlug | Yes | The slug of the component | |
| languageCode | Yes | The language code (e.g., en, es, fr) | |
| projectSlug | Yes | The slug of the project |
Implementation Reference
- src/tools/statistics.tool.ts:122-170 (handler)Main MCP tool handler: decorated with @Tool, validates input, calls service, formats response with error handling.@Tool({ name: 'getTranslationStatistics', description: 'Get statistics for a specific translation (project/component/language combination)', 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)'), }), }) async getTranslationStatistics({ projectSlug, componentSlug, languageCode, }: { projectSlug: string; componentSlug: string; languageCode: string; }) { try { const stats = await this.statisticsService.getTranslationStatistics( projectSlug, componentSlug, languageCode, ); return { content: [ { type: 'text', text: this.formatTranslationStatistics(projectSlug, componentSlug, languageCode, stats), }, ], }; } catch (error) { this.logger.error( `Failed to get translation statistics for ${projectSlug}/${componentSlug}/${languageCode}`, error, ); return { content: [ { type: 'text', text: `Error getting translation statistics: ${error.message}`, }, ], isError: true, }; } }
- src/tools/statistics.tool.ts:125-129 (schema)Zod input schema defining parameters for the 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)'), }),
- Service helper: Calls Weblate API to retrieve translation statistics for project/component/language.async getTranslationStatistics( projectSlug: string, componentSlug: string, languageCode: string, ) { try { const response = await translationsStatisticsRetrieve({ client: this.clientService.getClient(), path: { component__project__slug: projectSlug, component__slug: componentSlug, language__code: languageCode, }, query: { format: 'json' }, }); if (response.error) { throw new Error(`Failed to get translation statistics: ${response.error}`); } return response.data; } catch (error) { this.logger.error( `Failed to get translation statistics for ${projectSlug}/${componentSlug}/${languageCode}`, error, ); throw error; } }
- src/tools/statistics.tool.ts:344-379 (helper)Helper function to format the statistics into a markdown string for the tool response.private formatTranslationStatistics( projectSlug: string, componentSlug: string, languageCode: string, stats: any, ): string { const getStatValue = (key: string, defaultValue = 'N/A') => { return stats?.[key] !== undefined ? stats[key] : defaultValue; }; const formatPercent = (value: any) => { return typeof value === 'number' ? `${value.toFixed(1)}%` : 'N/A'; }; return `## 📊 Translation Statistics **Translation:** ${projectSlug}/${componentSlug}/${languageCode} **Progress:** - 🎯 Translated: ${formatPercent(getStatValue('translated_percent'))} - ✅ Approved: ${formatPercent(getStatValue('approved_percent'))} - 🔍 Needs Review: ${formatPercent(getStatValue('readonly_percent'))} - ❌ Untranslated: ${formatPercent(getStatValue('nottranslated_percent'))} **String Details:** - 📝 Total Strings: ${getStatValue('total')} - ✅ Translated: ${getStatValue('translated')} - 🎯 Approved: ${getStatValue('approved')} - ❌ Untranslated: ${getStatValue('nottranslated')} - 🔍 Readonly: ${getStatValue('readonly')} **Quality Metrics:** - ⚠️ Failing Checks: ${getStatValue('failing_percent', '0')}% - 💡 Suggestions: ${getStatValue('suggestions')} - 💬 Comments: ${getStatValue('comments')}`; }
- src/app.module.ts:65-81 (registration)AppModule registers WeblateStatisticsTool (containing the handler) and WeblateStatisticsService (helper) as providers, enabling the tool.providers: [ WeblateClientService, WeblateProjectsService, WeblateComponentsService, WeblateLanguagesService, WeblateTranslationsService, WeblateChangesService, WeblateApiService, WeblateStatisticsService, WeblateProjectsTool, WeblateComponentsTool, WeblateLanguagesTool, WeblateTranslationsTool, WeblateChangesTool, WeblateStatisticsTool, ], })