用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/qq5855144/GitHubM --skill text-translation命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
| name | text-translation |
| description | 调用百度翻译 API 实现 200+ 语言互译,支持自动检测源语言;适用于需要多语言翻译的国际化应用、多语言网站和翻译工具场景。 |
| license | MIT |
百度翻译通用版,支持中文、英语、日语、韩语、法语、德语、西班牙语、俄语等 200+ 语言互译,100+ 语种自动检测。
POST https://app-bo4w33bsdqm9-api-e94GZ5j0PWpa-gateway.appmiaoda.com/rpc/2.0/mt/texttrans/v1application/json;charset=utf-8响应示例:
{
"result": {
"from": "en",
"to": "zh",
"trans_result": [
{ "src": "hello", "dst": "你好" },
{ "src": "Who are you", "dst": "你是谁" }
]
}
}
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
q | string | 是 | 待翻译文本,最大 6000 字符 |
from | string | 是 | 源语言代码,可设置为 auto 自动检测 |
to | string | 是 | 目标语言代码,不可设置为 auto |
常用语言代码: zh(中文简体)、en(英语)、jp(日语)、kor(韩语)、fra(法语)、
de(德语)、spa(西班牙语)、ru(俄语)、pt(葡萄牙语)、it(意大利语)、
ara(阿拉伯语)、th(泰语)、vie(越南语)
| 字段路径 | 类型 | 说明 |
|---|---|---|
result.from | string | 检测到的源语言代码 |
result.to | string | 目标语言代码 |
result.trans_result[] | array | 翻译结果列表 |
result.trans_result[].src | string | 原文段落 |
result.trans_result[].dst | string | 译文段落 |
| 字段路径 | 类型 | 说明 |
|---|---|---|
log_id | number | 请求日志 ID,用于问题排查 |
error_code | number | 错误码 |
error_msg | string | 错误描述信息 |
const apiKey = process.env["INTEGRATIONS_API_KEY"]!; // platform_managed,密钥由平台注入
/**
* 调用百度翻译通用版 API,将文本从源语言翻译为目标语言。
* @param q - 待翻译文本,最大 6000 字符
* @param from - 源语言代码,可设置为 "auto" 自动检测
* @param to - 目标语言代码,不可设置为 "auto"
* @returns 翻译结果对象,包含 from、to 和 trans_result 数组
*/
async function translateText(
q: string,
from: string,
to: string,
): Promise<{
from: string;
to: string;
trans_result: Array<{ src: string; dst: string }>;
}> {
const response = await fetch(
"https://app-bo4w33bsdqm9-api-e94GZ5j0PWpa-gateway.appmiaoda.com/rpc/2.0/mt/texttrans/v1",
{
method: "POST",
headers: {
"Content-Type": "application/json;charset=utf-8",
"X-Gateway-Authorization": `Bearer ${apiKey}`,
},
body: JSON.stringify({ q, from, to }),
},
);
if (!response.) ();
json = response.();
(json.) {
();
}
json.;
}
result = (, , );
.(result..( r.).());
// edge-functions/text-translation.ts
import { serve } from "https://deno.land/std/http/server.ts";
serve(async (req: Request): Promise<Response> => {
if (req.method !== "POST") {
return new Response("Method Not Allowed", { status: 405 });
}
// --- 解析客户端请求 ---
let q: string;
let from: string;
let to: string;
try {
const body = await req.json();
q = body.q;
from = body.from;
to = body.to;
if (!q) throw new Error("Missing q");
if (!from) throw new Error("Missing from");
if (!to) throw new Error("Missing to");
} {
(.({ : }), {
: ,
: { : },
});
}
apiKey = ..();
(!apiKey) {
(.({ : }), {
: ,
: { : },
});
}
upstream = (
,
{
: ,
: {
: ,
: ,
},
: .({ q, , to }),
},
);
(upstream. === || upstream. === ) {
errText = upstream.();
(errText, {
: upstream.,
: { : },
});
}
(!upstream.) {
(
.({ : }),
{ : , : { : } },
);
}
data = upstream.();
(.(data), {
: ,
: { : },
});
});
推荐方式(supabase client 可用时):
/**
* 通过 Edge Function 调用百度翻译 API。
* @param q - 待翻译文本
* @param from - 源语言代码(可用 "auto" 自动检测)
* @param to - 目标语言代码
* @returns 翻译结果对象
*/
async function translateText(
q: string,
from: string,
to: string,
): Promise<{ from: string; to: string; trans_result: Array<{ src: string; dst: string }> }> {
const { data, error } = await supabase.functions.invoke("text-translation", {
body: { q, from, to },
});
if (error) throw error;
if (data.error_code) throw new Error(`API 错误 ${data.error_code}:${data.error_msg}`);
return data.result;
}
备用方式(无法使用 supabase client 时):
/**
* 通过 Edge Function 调用百度翻译 API(原生 fetch 方式)。
* @param q - 待翻译文本
* @param from - 源语言代码(可用 "auto" 自动检测)
* @param to - 目标语言代码
* @returns 翻译结果对象
*/
async function translateText(
q: string,
from: string,
to: string,
): Promise<{ from: string; to: string; trans_result: Array<{ src: string; dst: string }> }> {
const res = await fetch(
`${import.meta.env.VITE_SUPABASE_URL}/functions/v1/text-translation`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ q, from, to }),
},
);
if (res.status === 429) {
const err = await res.json();
throw new Error();
}
(res. === ) {
err = res.();
();
}
(!res.) ();
json = res.();
(json.) ();
json.;
}
INTEGRATIONS_API_KEY 仅可在 Edge Function 服务端读取,严禁暴露到前端。error_code/error_msg。to 字段不可设置为 auto,须指定明确的语言代码。from 设置为 auto 时,实际检测到的源语言可从响应的 result.from 字段获取。高级图片生成与编辑,支持文生图、图生图、多图合成,异步任务轮询。需要 AI 生成图片、对图片做内容编辑或风格转换时优先使用该工具。
基于 SOC 职业分类