Skip to main content
Glama

localizationFindLongValues

Identify translation entries exceeding a specified character count in localization files to maintain consistency and readability across languages.

Instructions

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYes
thresholdYes
languageNo
limitNo

Implementation Reference

  • main.ts:456-475 (registration)
    Registers the MCP tool 'localizationFindLongValues' with input schema (filePath: string, threshold: number, optional language and limit) and delegates execution to LocalizationTool.findLongValues from tools/localizationTool.ts.
    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 : "未知錯誤"}` }] }; } }
  • Core handler implementation: Loads CSV data via cached getCSVData, iterates over entries and languages, collects those exceeding threshold length, sorts by descending length, limits results, returns LongValueResult.
    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; } }
  • TypeScript interface defining the output schema for the tool's results: total count and array of long value entries with key, language, value, and length.
    export interface LongValueResult { totalResults: number; entries: Array<{ key: string; language: string; value: string; length: number; }>; }
  • Zod schema defining the input parameters for the tool: required filePath and threshold, optional language and limit.
    { filePath: z.string(), threshold: z.number(), language: z.string().optional(), limit: z.number().optional()
  • Cached CSV data loader used by the handler: reads and parses CSV file content, handles manual parsing fallback, manages 30s cache to avoid repeated reads.
    private static async getCSVData(filePath: string, force = false): Promise<LocalizationEntry[]> { const now = Date.now(); const cached = this.cache.get(filePath); // 如果緩存有效且不需要強制重新讀取 if (!force && cached && (now - cached.timestamp < this.CACHE_EXPIRY)) { return cached.data; } try { // 讀取並解析CSV檔案 const content = await this.readCSVFileRaw(filePath); const records = this.parseCSVContent(content); // 更新緩存 this.cache.set(filePath, { data: records, timestamp: now }); return records; } catch (error) { console.error(`解析CSV檔案失敗: ${error instanceof Error ? error.message : '未知錯誤'}`); throw error; } }

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