Skip to main content
Glama
oofengoo

MCP-Serve 多语言翻译服务

by oofengoo

translationI18n

Translate text across multiple languages using AI-powered multilingual capabilities. Integrates with external APIs for automatic extraction and resource management.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputYes

Implementation Reference

  • The handler function that implements the core logic of the 'translationI18n' tool. It extracts text blocks wrapped in ##...## using regex, optionally translates to English if port is 5500, calls geti18n to obtain aliases, replaces the original blocks, and returns the modified content.
    async ({ input }) => { // 匹配所有 ##...## 的内容 const regex = /##([\s\S]+?)##/g; let matches = input.matchAll(regex); let result = input; for (const match of matches) { const value = match[1]; if (!value) continue; let params: Record<string, any> = { language: 1, autoAlias: true, value: value, }; if (port === "5500") { params.valueEn = await TranslateToEn(value); } // 调用多语言接口 const alias = await geti18n(params); if (alias) { result = result.replace(match[0], alias); } } return { content: [ { type: "text", text: result, }, ], }; }
  • src/index.ts:13-49 (registration)
    The registration of the 'translationI18n' tool using server.tool(), including the input schema and inline handler function.
    server.tool( "translationI18n", { input: z.string(), }, async ({ input }) => { // 匹配所有 ##...## 的内容 const regex = /##([\s\S]+?)##/g; let matches = input.matchAll(regex); let result = input; for (const match of matches) { const value = match[1]; if (!value) continue; let params: Record<string, any> = { language: 1, autoAlias: true, value: value, }; if (port === "5500") { params.valueEn = await TranslateToEn(value); } // 调用多语言接口 const alias = await geti18n(params); if (alias) { result = result.replace(match[0], alias); } } return { content: [ { type: "text", text: result, }, ], }; } );
  • Input schema for the tool, defined as a string using Zod.
    { input: z.string(), },
  • Helper function that makes a POST request to the i18n API endpoint to add a resource and retrieve the translation alias, used by the tool handler.
    async function geti18n(params: Record<string, any>) { const res = await http.post( "/MultiLanguageResource/AddResource", params, baseConfig ); if (res.Data) { return res.Data.ResourceAlias; } else { return ""; } }
  • Helper function to translate text to English via API, conditionally used in the handler when port === '5500'.
    async function TranslateToEn(text: string) { const res = await http.get( "/MultiLanguageResource/TranslateToEn", { text }, baseConfig ); return res; }

Other Tools

Related 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/oofengoo/mcp-serve-learn'

If you have feedback or need assistance with the MCP directory API, please join our Discord server