Skip to main content
Glama
mmntm

Weblate MCP Server

by mmntm

getComponentLanguageProgress

Retrieve translation progress statistics for all languages in a Weblate component to monitor localization status and identify areas needing attention.

Instructions

Get translation progress for all languages in a component

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectSlugYesThe slug of the project
componentSlugYesThe slug of the component

Implementation Reference

  • Main handler for the MCP tool 'getComponentLanguageProgress'. Includes @Tool decorator with name, description, Zod input schema, and the async function that delegates to statistics service, formats output, and handles errors.
    @Tool({
      name: 'getComponentLanguageProgress',
      description: 'Get translation progress for all languages in a component',
      parameters: z.object({
        projectSlug: z.string().describe('The slug of the project'),
        componentSlug: z.string().describe('The slug of the component'),
      }),
    })
    async getComponentLanguageProgress({
      projectSlug,
      componentSlug,
    }: {
      projectSlug: string;
      componentSlug: string;
    }) {
      try {
        const progress = await this.statisticsService.getComponentLanguageProgress(
          projectSlug,
          componentSlug,
        );
    
        return {
          content: [
            {
              type: 'text',
              text: this.formatComponentLanguageProgress(projectSlug, componentSlug, progress),
            },
          ],
        };
      } catch (error) {
        this.logger.error(
          `Failed to get component language progress for ${projectSlug}/${componentSlug}`,
          error,
        );
        return {
          content: [
            {
              type: 'text',
              text: `Error getting component language progress: ${error.message}`,
            },
          ],
          isError: true,
        };
      }
    }
  • Zod schema defining input parameters for the tool: projectSlug and componentSlug.
    parameters: z.object({
      projectSlug: z.string().describe('The slug of the project'),
      componentSlug: z.string().describe('The slug of the component'),
    }),
  • Core service method implementing the logic to fetch translation progress: lists project languages and retrieves statistics for each in the component.
    async getComponentLanguageProgress(projectSlug: string, componentSlug: string) {
      try {
        // Get available languages for the project
        const languages = await this.languagesService.listLanguages(projectSlug);
    
        // Get translation statistics for each language
        const languageProgress = await Promise.all(
          languages.map(async (language) => {
            try {
              const stats = await this.getTranslationStatistics(
                projectSlug,
                componentSlug,
                language.code,
              );
              return {
                language: language.name,
                code: language.code,
                statistics: stats,
              };
            } catch (error) {
              this.logger.warn(
                `Failed to get translation stats for ${language.code} in ${componentSlug}`,
                error,
              );
              return {
                language: language.name,
                code: language.code,
                statistics: null,
                error: error.message,
              };
            }
          }),
        );
    
        return languageProgress;
      } catch (error) {
        this.logger.error(
          `Failed to get component language progress for ${projectSlug}/${componentSlug}`,
          error,
        );
        throw error;
      }
    }
  • Formatter helper that converts language progress data into a formatted Markdown string with progress bars and statistics per language.
      private formatComponentLanguageProgress(
        projectSlug: string,
        componentSlug: string,
        progress: any[],
      ): string {
        let result = `## 🌐 Language Progress: ${projectSlug}/${componentSlug}\n\n`;
    
        progress.forEach((lang: any, index: number) => {
          if (lang.statistics) {
            const stats = lang.statistics;
            const formatPercent = (value: any) => {
              return typeof value === 'number' ? `${value.toFixed(1)}%` : 'N/A';
            };
    
            const progressBar = this.generateProgressBar(stats.translated_percent || 0);
    
            result += `**${index + 1}. ${lang.language}** (${lang.code})
    ${progressBar} ${formatPercent(stats.translated_percent)}
    - βœ… Approved: ${formatPercent(stats.approved_percent)}
    - πŸ“ Total: ${stats.total || 'N/A'} | Translated: ${stats.translated || 'N/A'}
    
    `;
          } else {
            result += `**${index + 1}. ${lang.language}** (${lang.code})
    - ❌ Error: ${lang.error || 'Unable to load statistics'}
    
    `;
          }
        });
    
        return result;
      }
  • Registration of the WeblateStatisticsTool class (containing the tool handler) as a provider in the NestJS AppModule.
    WeblateStatisticsTool,

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