Skip to main content
Glama

localizationUpdate

Update translation content in localization files by modifying specific keys and language values to maintain accurate multilingual resources.

Instructions

更新現有翻譯項目的內容

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYes
keyYes
updateDataYes

Implementation Reference

  • Core handler method that loads the CSV data, finds the entry by key, applies partial updates to language fields, writes back to file, and updates cache. Handles errors and validation.
    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; } }
  • main.ts:372-395 (registration)
    MCP server tool registration for 'localizationUpdate', including Zod input schema validation and wrapper handler that delegates to LocalizationTool.updateEntry.
    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 : "未知錯誤"}` }] }; } } );
  • TypeScript interface defining the structure of a localization entry used for type safety in update operations and data handling.
    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