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
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | ||
| key | Yes | ||
| updateData | Yes |
Implementation Reference
- tools/localizationTool.ts:380-412 (handler)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; } }
- tools/localizationTool.ts:8-14 (schema)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 : "未知錯誤"}` }] }; } } );