Skip to main content
Glama

localizationSearch

Search for translation items containing specific text in localization files to find and manage multilingual content across projects.

Instructions

搜尋包含特定文字的翻譯項目

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYes
searchTextYes
languageNo
limitNo

Implementation Reference

  • main.ts:323-343 (registration)
    Registration of the 'localizationSearch' MCP tool, including description, Zod input schema, and thin async handler that delegates to LocalizationTool.searchEntries and formats the response.
    server.tool("localizationSearch", "搜尋包含特定文字的翻譯項目", { filePath: z.string(), searchText: z.string(), language: z.string().optional(), limit: z.number().optional() }, async ({ filePath, searchText, language = '', limit = 10 }) => { try { const results = await LocalizationTool.searchEntries(filePath, searchText, language, limit); return { content: [{ type: "text", text: JSON.stringify(results, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `搜尋失敗: ${error instanceof Error ? error.message : "未知錯誤"}` }] }; } } );
  • Zod input schema defining parameters for the localizationSearch tool: filePath (string), searchText (string), optional language (string), optional limit (number).
    { filePath: z.string(), searchText: z.string(), language: z.string().optional(), limit: z.number().optional() },
  • Core helper function LocalizationTool.searchEntries that loads CSV data from file, performs case-insensitive text search in specified language or all languages (excluding Key), limits results, and returns SearchResult with total and entries.
    static async searchEntries( filePath: string, searchText: string, language: string = '', limit: number = 10 ): Promise<SearchResult> { try { const records = await this.getCSVData(filePath); const searchTextLower = searchText.toLowerCase(); // 搜尋邏輯 let results: LocalizationEntry[] = []; if (language) { // 僅搜尋指定語言 results = records.filter(entry => entry[language] && entry[language].toLowerCase().includes(searchTextLower) ); } else { // 搜尋所有欄位 results = records.filter(entry => Object.entries(entry).some(([key, value]) => key !== 'Key' && value && value.toLowerCase().includes(searchTextLower) ) ); } // 限制返回數量 const limitedResults = results.slice(0, limit); return { totalResults: results.length, entries: limitedResults }; } catch (error) { console.error(`搜尋文字失敗: ${error instanceof Error ? error.message : '未知錯誤'}`); throw error; } }
  • Type definition for SearchResult returned by searchEntries.
    export interface SearchResult { totalResults: number; entries: LocalizationEntry[]; }
  • Type definition for individual localization entry in CSV.
    export interface LocalizationEntry { Key: string; 'zh-TW': string; 'zh-CN': string; en: string; [key: string]: string; // 其他可能的語言欄位 }

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