Skip to main content
Glama

localizationGetByKey

Retrieve specific translation entries by key from localization files to support multilingual application development and content management.

Instructions

根據Key查詢特定翻譯項目

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYes
keyYes

Implementation Reference

  • Core handler logic for retrieving a localization entry by key: loads CSV data from cache or parses file, finds matching entry by Key field, returns the entry or null. Handles errors by throwing.
    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, used as return type for getEntryByKey.
    export interface LocalizationEntry { Key: string; 'zh-TW': string; 'zh-CN': string; en: string; [key: string]: string; // 其他可能的語言欄位 }
  • main.ts:305-320 (registration)
    MCP server tool registration for 'localizationGetByKey', includes description, Zod input schema, and thin async handler that calls the core implementation and returns JSON-formatted result or error.
    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)
    Thin MCP tool handler wrapper: invokes LocalizationTool.getEntryByKey with inputs, returns MCP-formatted text content with JSON entry or error message.
    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 : "未知錯誤"}` }] }; } }
  • Inline Zod schema for tool inputs: filePath (CSV file path) and key (localization key to lookup).
    { filePath: z.string(), key: z.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