localizationExportJson
Export translations for a specific language into a JSON format, enabling efficient localization management for projects using the GonMCPtool MCP server.
Instructions
將特定語言的翻譯導出為JSON格式
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | ||
| language | Yes |
Implementation Reference
- tools/localizationTool.ts:449-467 (handler)Core handler function that reads the CSV localization file, extracts translations for the specified language into a key-value object, and returns a formatted JSON string.static async exportLanguageAsJson(filePath: string, language: string): Promise<string> { try { const records = await this.getCSVData(filePath); // 創建Key-Value的映射 const langData: Record<string, string> = {}; for (const entry of records) { if (entry.Key && entry[language]) { langData[entry.Key] = entry[language]; } } return JSON.stringify(langData, null, 2); } catch (error) { console.error(`匯出語言資料失敗: ${error instanceof Error ? error.message : '未知錯誤'}`); throw error; } }
- main.ts:418-418 (schema)Zod input schema defining parameters: filePath (string) and language (string).{ filePath: z.string(), language: z.string() },
- main.ts:416-431 (registration)Tool registration with name, description, input schema, and thin async handler that calls the core LocalizationTool.exportLanguageAsJson method and formats the MCP response.server.tool("localizationExportJson", "將特定語言的翻譯導出為JSON格式", { filePath: z.string(), language: z.string() }, async ({ filePath, language }) => { try { const result = await LocalizationTool.exportLanguageAsJson(filePath, language); return { content: [{ type: "text", text: result }] }; } catch (error) { return { content: [{ type: "text", text: `匯出失敗: ${error instanceof Error ? error.message : "未知錯誤"}` }] }; } } );