Skip to main content
Glama

localizationFindLongValues

Identify and extract translation entries exceeding a specified character length threshold in localization files for efficient review and optimization.

Instructions

查找超過特定字數的翻譯項目

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYes
languageNo
limitNo
thresholdYes

Implementation Reference

  • Core handler function that scans CSV localization files, identifies entries where text values exceed the character threshold (in specified language or all), sorts by length descending, and returns limited results with metadata.
    static async findLongValues( filePath: string, threshold: number, language: string = '', limit: number = 50 ): Promise<LongValueResult> { try { if (threshold <= 0) { throw new Error('字數閾值必須大於0'); } const records = await this.getCSVData(filePath); // 用於存儲結果的陣列 const longValues: Array<{ key: string; language: string; value: string; length: number; }> = []; // 遍歷所有記錄 for (const entry of records) { if (!entry.Key) continue; // 取得要檢查的語言欄位 const languagesToCheck = language ? [language] : Object.keys(entry).filter(key => key !== 'Key'); // 檢查每個語言欄位 for (const lang of languagesToCheck) { if (entry[lang] && entry[lang].length > threshold) { longValues.push({ key: entry.Key, language: lang, value: entry[lang], length: entry[lang].length }); } } } // 依長度降序排序 longValues.sort((a, b) => b.length - a.length); // 限制返回數量 const limitedResults = longValues.slice(0, limit); return { totalResults: longValues.length, entries: limitedResults }; } catch (error) { console.error(`搜尋長文字失敗: ${error instanceof Error ? error.message : '未知錯誤'}`); throw error; } }
  • main.ts:456-476 (registration)
    Registers the MCP tool 'localizationFindLongValues' with Zod input schema validation and an async handler that delegates execution to LocalizationTool.findLongValues, formatting results as JSON text content.
    server.tool("localizationFindLongValues", "查找超過特定字數的翻譯項目", { filePath: z.string(), threshold: z.number(), language: z.string().optional(), limit: z.number().optional() }, async ({ filePath, threshold, language = '', limit = 50 }) => { try { const results = await LocalizationTool.findLongValues(filePath, threshold, language, limit); return { content: [{ type: "text", text: JSON.stringify(results, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `搜尋超長文字失敗: ${error instanceof Error ? error.message : "未知錯誤"}` }] }; } } );
  • TypeScript interface defining the output structure for long value search results, used by the handler.
    export interface LongValueResult { totalResults: number; entries: Array<{ key: string; language: string; value: string; length: number; }>; }

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/GonTwVn/GonMCPtool'

If you have feedback or need assistance with the MCP directory API, please join our Discord server