Skip to main content
Glama

localizationAdd

Add a complete localization entry with translations for zh-TW, zh-CN, and en into a specified file path using this tool in the GonMCPtool MCP server.

Instructions

新增一個完整的翻譯項目

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
entryYes
filePathYes

Implementation Reference

  • main.ts:346-369 (registration)
    Registers the 'localizationAdd' MCP tool, defining its input schema (filePath and entry object with Key, zh-TW, zh-CN, en) and a thin async handler that calls LocalizationTool.addEntry and formats the response.
    server.tool("localizationAdd", "新增一個完整的翻譯項目", { filePath: z.string(), entry: z.object({ Key: z.string(), "zh-TW": z.string(), "zh-CN": z.string(), en: z.string() }).passthrough() }, async ({ filePath, entry }) => { try { const result = await LocalizationTool.addEntry(filePath, entry as LocalizationEntry); return { content: [{ type: "text", text: result }] }; } catch (error) { return { content: [{ type: "text", text: `新增失敗: ${error instanceof Error ? error.message : "未知錯誤"}` }] }; } } );
  • Core handler implementation in LocalizationTool.addEntry: validates input key, checks for existing key, appends new entry to CSV records using cache-aware getCSVData, writes back via writeCSVData, returns success/error message.
    static async addEntry(filePath: string, entry: LocalizationEntry): Promise<string> { try { // 檢查輸入是否有效 if (!entry.Key) { return '錯誤: Key 不能為空'; } const records = await this.getCSVData(filePath); // 檢查Key是否已存在 if (records.some(e => e.Key === entry.Key)) { return `錯誤: Key "${entry.Key}" 已存在`; } // 新增項目 records.push({...entry}); // 寫回檔案並更新緩存 await this.writeCSVData(filePath, records); return `成功新增Key "${entry.Key}"`; } catch (error) { console.error(`新增翻譯項失敗: ${error instanceof Error ? error.message : '未知錯誤'}`); throw error; } }
  • TypeScript interface defining the structure of a localization entry (Key and language fields), used for type safety in addEntry method and tool input.
    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