localizationDelete
Remove translation entries for specific keys from localization files to manage multilingual content effectively.
Instructions
刪除指定Key的翻譯項目
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | ||
| key | Yes |
Implementation Reference
- tools/localizationTool.ts:420-441 (handler)The main handler function that implements the deletion logic: loads CSV data from cache/file, finds the entry by key, removes it, and writes back to the file updating cache.static async deleteEntry(filePath: string, key: string): Promise<string> { try { const records = await this.getCSVData(filePath); // 找到要刪除的項目索引 const index = records.findIndex(entry => entry.Key === key); if (index === -1) { return `錯誤: Key "${key}" 不存在`; } // 刪除項目 records.splice(index, 1); // 寫回檔案並更新緩存 await this.writeCSVData(filePath, records); return `成功刪除Key "${key}"`; } catch (error) { console.error(`刪除翻譯項失敗: ${error instanceof Error ? error.message : '未知錯誤'}`); throw error; } }
- main.ts:398-413 (registration)Registers the 'localizationDelete' tool with the MCP server, defining input schema and wrapping the LocalizationTool.deleteEntry handler.server.tool("localizationDelete", "刪除指定Key的翻譯項目", { filePath: z.string(), key: z.string() }, async ({ filePath, key }) => { try { const result = await LocalizationTool.deleteEntry(filePath, key); return { content: [{ type: "text", text: result }] }; } catch (error) { return { content: [{ type: "text", text: `刪除失敗: ${error instanceof Error ? error.message : "未知錯誤"}` }] }; } } );
- main.ts:400-400 (schema)Zod input schema validation for the tool: filePath (string) and key (string).{ filePath: z.string(), key: z.string() },
- tools/localizationTool.ts:8-14 (schema)TypeScript interface defining the structure of a localization entry in the CSV.export interface LocalizationEntry { Key: string; 'zh-TW': string; 'zh-CN': string; en: string; [key: string]: string; // 其他可能的語言欄位 }