localizationFindMissing
Identify missing translations for a specific language in localization files to ensure consistent multilingual support and improve language coverage.
Instructions
查找有Key值但缺少特定語言翻譯的項目
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | ||
| language | Yes | ||
| limit | No |
Implementation Reference
- tools/localizationTool.ts:524-552 (handler)The core handler function `findMissingTranslations` that scans the CSV file for entries with a Key but missing translation in the specified language. Filters records where the language field is empty/null/undefined/whitespace.static async findMissingTranslations(filePath: string, language: string, limit: number = 50): Promise<SearchResult> { try { if (!language) { throw new Error('必須指定要檢查的語言'); } const records = await this.getCSVData(filePath); // 尋找指定語言翻譯為空的項目 const missingEntries = records.filter(entry => { // 確保有Key且該語言的翻譯為空 return entry.Key && (entry[language] === undefined || entry[language] === null || entry[language].trim() === ''); }); // 限制返回數量 const limitedResults = missingEntries.slice(0, limit); return { totalResults: missingEntries.length, entries: limitedResults }; } catch (error) { console.error(`搜尋缺少翻譯的項目失敗: ${error instanceof Error ? error.message : '未知錯誤'}`); throw error; } }
- main.ts:434-453 (registration)Tool registration using server.tool(), including inline handler wrapper that delegates to LocalizationTool.findMissingTranslations and formats the MCP response.server.tool("localizationFindMissing", "查找有Key值但缺少特定語言翻譯的項目", { filePath: z.string(), language: z.string(), limit: z.number().optional() }, async ({ filePath, language, limit = 50 }) => { try { const results = await LocalizationTool.findMissingTranslations(filePath, language, limit); return { content: [{ type: "text", text: JSON.stringify(results, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `搜尋缺少翻譯項目失敗: ${error instanceof Error ? error.message : "未知錯誤"}` }] }; } } );
- main.ts:436-440 (schema)Zod input schema defining parameters: filePath (string), language (string), limit (number, optional).{ filePath: z.string(), language: z.string(), limit: z.number().optional() },
- tools/localizationTool.ts:19-22 (schema)TypeScript interface for the output structure returned by the handler: totalResults and entries array.export interface SearchResult { totalResults: number; entries: LocalizationEntry[]; }