Skip to main content
Glama

localizationGetByKey

Retrieve specific translation items by key from a file using this tool. Input the file path and key to fetch the required localization data directly.

Instructions

根據Key查詢特定翻譯項目

Input Schema

NameRequiredDescriptionDefault
filePathYes
keyYes

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "filePath": { "type": "string" }, "key": { "type": "string" } }, "required": [ "filePath", "key" ], "type": "object" }

Implementation Reference

  • main.ts:305-320 (registration)
    Registration of the 'localizationGetByKey' tool using server.tool(), including description, input schema, and inline handler function.
    server.tool("localizationGetByKey", "根據Key查詢特定翻譯項目", { filePath: z.string(), key: z.string() }, async ({ filePath, key }) => { try { const entry = await LocalizationTool.getEntryByKey(filePath, key); return { content: [{ type: "text", text: JSON.stringify(entry, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `查詢失敗: ${error instanceof Error ? error.message : "未知錯誤"}` }] }; } } );
  • main.ts:308-319 (handler)
    The inline asynchronous handler function for the tool, which invokes LocalizationTool.getEntryByKey, handles the result or error, and returns formatted content.
    async ({ filePath, key }) => { try { const entry = await LocalizationTool.getEntryByKey(filePath, key); return { content: [{ type: "text", text: JSON.stringify(entry, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `查詢失敗: ${error instanceof Error ? error.message : "未知錯誤"}` }] }; } }
  • Zod input schema defining parameters: filePath (string) and key (string).
    { filePath: z.string(), key: z.string() },
  • Core helper method LocalizationTool.getEntryByKey that retrieves CSV data (with caching), finds the entry matching the given key, and returns it or null.
    static async getEntryByKey(filePath: string, key: string): Promise<LocalizationEntry | null> { try { // 讀取所有資料 const records = await this.getCSVData(filePath); // 尋找匹配的Key const foundEntry = records.find(entry => entry.Key === key); return foundEntry || null; } catch (error) { console.error(`讀取Key失敗: ${error instanceof Error ? error.message : '未知錯誤'}`); throw error; } }
  • TypeScript interface defining the structure of a localization entry with Key and language fields.
    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