Skip to main content
Glama

localizationUpdate

Update existing translation content by specifying file path, key, and new text for supported languages like zh-TW, zh-CN, and en within the MCP server environment.

Instructions

更新現有翻譯項目的內容

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYes
keyYes
updateDataYes

Implementation Reference

  • Core handler logic for updating a localization entry by key: loads CSV data from cache or file, finds the entry, applies partial updates to language fields, writes back to file, and updates cache. Returns success/error message.
    static async updateEntry( filePath: string, key: string, updateData: Partial<Omit<LocalizationEntry, 'Key'>> ): Promise<string> { try { const records = await this.getCSVData(filePath); // 找到要更新的項目索引 const index = records.findIndex(entry => entry.Key === key); if (index === -1) { return `錯誤: Key "${key}" 不存在`; } // 更新欄位 (確保過濾掉任何undefined值) const validUpdateData = Object.fromEntries( Object.entries(updateData).filter(([_, value]) => value !== undefined) ) as Record<string, string>; records[index] = { ...records[index], ...validUpdateData }; // 寫回檔案並更新緩存 await this.writeCSVData(filePath, records); return `成功更新Key "${key}"`; } catch (error) { console.error(`更新翻譯項失敗: ${error instanceof Error ? error.message : '未知錯誤'}`); throw error; } }
  • TypeScript interface defining the structure of a localization entry with Key and language fields (zh-TW, zh-CN, en, extensible). Used for typing updateData in the tool.
    export interface LocalizationEntry { Key: string; 'zh-TW': string; 'zh-CN': string; en: string; [key: string]: string; // 其他可能的語言欄位 }
  • main.ts:372-395 (registration)
    MCP server tool registration for 'localizationUpdate': defines Zod input schema for filePath, key, and optional language updates; inline handler delegates to LocalizationTool.updateEntry and formats MCP response.
    server.tool("localizationUpdate", "更新現有翻譯項目的內容", { filePath: z.string(), key: z.string(), updateData: z.object({ "zh-TW": z.string().optional(), "zh-CN": z.string().optional(), en: z.string().optional() }).passthrough() }, async ({ filePath, key, updateData }) => { try { const result = await LocalizationTool.updateEntry(filePath, key, updateData as Partial<Omit<LocalizationEntry, "Key">>); return { content: [{ type: "text", text: result }] }; } catch (error) { return { content: [{ type: "text", text: `更新失敗: ${error instanceof Error ? error.message : "未知錯誤"}` }] }; } } );

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