Skip to main content
Glama

localizationExportJson

Export translations for a specific language to JSON format from localization files. Specify file path and language to generate structured translation data.

Instructions

將特定語言的翻譯導出為JSON格式

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYes
languageYes

Implementation Reference

  • The core handler function that reads the CSV localization file, extracts translations for the specified language, and returns them as a formatted JSON object.
    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:416-430 (registration)
    Registers the 'localizationExportJson' tool with the MCP server, defines the input schema, and provides a wrapper handler that calls the core implementation 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 : "未知錯誤"}` }]
                };
            }
        }
  • Zod schema defining the input parameters: filePath (string) and language (string).
    { filePath: z.string(), language: z.string() },
  • TypeScript interface defining the structure of localization entries in the CSV file, used by the tool's parsing logic.
    export interface LocalizationEntry {
      Key: string;
      'zh-TW': string;
      'zh-CN': string;
      en: string;
      [key: string]: string; // 其他可能的語言欄位
    }
  • Helper method that loads and parses the CSV file into LocalizationEntry array, with caching for efficiency. Used by the handler.
    private static async getCSVData(filePath: string, force = false): Promise<LocalizationEntry[]> {
      const now = Date.now();
      const cached = this.cache.get(filePath);
    
      // 如果緩存有效且不需要強制重新讀取
      if (!force && cached && (now - cached.timestamp < this.CACHE_EXPIRY)) {
        return cached.data;
      }
    
      try {
        // 讀取並解析CSV檔案
        const content = await this.readCSVFileRaw(filePath);
        const records = this.parseCSVContent(content);
        
        // 更新緩存
        this.cache.set(filePath, {
          data: records,
          timestamp: now
        });
        
        return records;
      } catch (error) {
        console.error(`解析CSV檔案失敗: ${error instanceof Error ? error.message : '未知錯誤'}`);
        throw error;
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool exports translations but doesn't clarify whether this is a read-only operation, if it modifies data, what permissions are needed, or how the export is delivered (e.g., file creation vs. data return). For a tool with two parameters and no annotation coverage, this leaves significant behavioral gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's function without unnecessary words. It's appropriately sized for a simple export operation and front-loaded with the core action.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has 2 parameters with 0% schema coverage, no annotations, and no output schema, the description is insufficient. It doesn't explain parameter meanings, behavioral traits (e.g., file system impact), or return values, leaving the agent with inadequate context to use the tool correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema has 0% description coverage, so parameters 'filePath' and 'language' are undocumented in the schema. The description mentions 'specific language' (hinting at the 'language' parameter) but doesn't explain 'filePath' at all (e.g., whether it's an input or output path). It adds minimal value beyond the schema, failing to compensate for the low coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('export') and resource ('translations for a specific language') with the output format ('JSON format'), making the purpose understandable. However, it doesn't differentiate from sibling tools like localizationGetByKey or localizationSearch, which might also retrieve translation data.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like localizationGetByKey (which retrieves by key) or localizationSearch (which searches translations). There's no mention of prerequisites, exclusions, or specific scenarios where exporting to JSON is preferred over other methods.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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