getTranslationStatistics
Retrieve statistics for a specific translation project, component, and language combination to monitor translation progress and status.
Instructions
Get statistics for a specific translation (project/component/language combination)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectSlug | Yes | The slug of the project | |
| componentSlug | Yes | The slug of the component | |
| languageCode | Yes | The language code (e.g., en, es, fr) |
Implementation Reference
- src/tools/statistics.tool.ts:122-170 (handler)The @Tool-decorated handler function implementing the core logic for getTranslationStatistics, which fetches data from the service and formats the output.@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 schema defining the input parameters for the getTranslationStatistics 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)'), }),
- src/app.module.ts:74-80 (registration)Registration of WeblateStatisticsTool (containing the getTranslationStatistics handler) in the AppModule providers.WeblateProjectsTool, WeblateComponentsTool, WeblateLanguagesTool, WeblateTranslationsTool, WeblateChangesTool, WeblateStatisticsTool, ],
- Helper service method that retrieves translation statistics from the Weblate API via translationsStatisticsRetrieve.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 method to format the translation statistics into a readable markdown string.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')}`; }