From 287a666e1b2bb155e86aa88ebace201d1e8a51f6 Mon Sep 17 00:00:00 2001
From: zhou zhou <3272660260@qq.com>
Date: 星期四, 19 三月 2026 13:26:02 +0800
Subject: [PATCH] #AI.国际化
---
rsf-admin/src/page/system/aiMcpMount/AiMcpMountToolsPanel.jsx | 55 ++++++++++++++++++++++++++++---------------------------
1 files changed, 28 insertions(+), 27 deletions(-)
diff --git a/rsf-admin/src/page/system/aiMcpMount/AiMcpMountToolsPanel.jsx b/rsf-admin/src/page/system/aiMcpMount/AiMcpMountToolsPanel.jsx
index 96edb0a..1b6158b 100644
--- a/rsf-admin/src/page/system/aiMcpMount/AiMcpMountToolsPanel.jsx
+++ b/rsf-admin/src/page/system/aiMcpMount/AiMcpMountToolsPanel.jsx
@@ -1,4 +1,5 @@
import React, { useEffect, useMemo, useState } from "react";
+import { useTranslate, useNotify } from "react-admin";
import {
Accordion,
AccordionDetails,
@@ -18,10 +19,9 @@
import PlayCircleOutlineOutlinedIcon from "@mui/icons-material/PlayCircleOutlineOutlined";
import PreviewOutlinedIcon from "@mui/icons-material/PreviewOutlined";
import ExpandMoreOutlinedIcon from "@mui/icons-material/ExpandMoreOutlined";
-import { useNotify } from "react-admin";
import { previewMcpTools, testMcpConnectivity, testMcpTool } from "@/api/ai/mcpMount";
-const parseInputSchema = (inputSchema) => {
+const parseInputSchema = (inputSchema, translate) => {
if (!inputSchema) {
return { pretty: "", fields: [], required: [], error: "" };
}
@@ -46,7 +46,7 @@
pretty: inputSchema,
fields: [],
required: [],
- error: `Input Schema 瑙f瀽澶辫触: ${error.message}`,
+ error: translate("ai.mcp.tools.schemaParseFailed", { message: error.message }),
};
}
};
@@ -118,6 +118,7 @@
const AiMcpMountToolsPanel = ({ mountId }) => {
const notify = useNotify();
+ const translate = useTranslate();
const [loading, setLoading] = useState(false);
const [tools, setTools] = useState([]);
const [error, setError] = useState("");
@@ -130,10 +131,10 @@
const schemaInfoMap = useMemo(() => {
return tools.reduce((result, tool) => {
- result[tool.name] = parseInputSchema(tool.inputSchema);
+ result[tool.name] = parseInputSchema(tool.inputSchema, translate);
return result;
}, {});
- }, [tools]);
+ }, [tools, translate]);
useEffect(() => {
if (!mountId) {
@@ -158,7 +159,7 @@
setInputs({});
setStructuredInputs({});
} catch (requestError) {
- setError(requestError.message || "鑾峰彇宸ュ叿鍒楄〃澶辫触");
+ setError(requestError.message || translate("ai.mcp.tools.loadFailed"));
} finally {
setLoading(false);
}
@@ -169,9 +170,9 @@
try {
const result = await testMcpConnectivity(mountId);
setConnectivity(result);
- notify(result?.message || "杩為�氭�ф祴璇曞畬鎴�");
+ notify(result?.message || translate("ai.mcp.connectivity.success"));
} catch (requestError) {
- const message = requestError.message || "杩為�氭�ф祴璇曞け璐�";
+ const message = requestError.message || translate("ai.mcp.connectivity.failed");
notify(message, { type: "error" });
} finally {
setTestingConnectivity(false);
@@ -210,7 +211,7 @@
const handleTest = async (toolName) => {
const inputJson = inputs[toolName];
if (!inputJson || !inputJson.trim()) {
- notify("璇疯緭鍏ュ伐鍏锋祴璇� JSON", { type: "warning" });
+ notify(translate("ai.mcp.tools.inputRequired"), { type: "warning" });
return;
}
setTestingToolName(toolName);
@@ -223,9 +224,9 @@
...prev,
[toolName]: result?.output || "",
}));
- notify(`宸ュ叿 ${toolName} 娴嬭瘯瀹屾垚`);
+ notify(translate("ai.mcp.tools.testSuccess", { name: toolName }));
} catch (requestError) {
- const message = requestError.message || "宸ュ叿娴嬭瘯澶辫触";
+ const message = requestError.message || translate("ai.mcp.tools.testFailed");
setOutputs((prev) => ({
...prev,
[toolName]: message,
@@ -239,7 +240,7 @@
if (!mountId) {
return (
<Alert severity="info" sx={{ mt: 2 }}>
- 淇濆瓨鎸傝浇鍚庡嵆鍙瑙堝伐鍏峰苟鎵ц娴嬭瘯銆�
+ {translate("ai.mcp.tools.saveBeforePreview")}
</Alert>
);
}
@@ -249,16 +250,16 @@
<Accordion defaultExpanded={false} sx={{ borderRadius: 3, overflow: "hidden" }}>
<AccordionSummary expandIcon={<ExpandMoreOutlinedIcon />}>
<Box flex={1}>
- <Typography variant="h6">宸ュ叿棰勮涓庢祴璇�</Typography>
+ <Typography variant="h6">{translate("ai.mcp.tools.title")}</Typography>
<Typography variant="body2" color="text.secondary">
- 鏀寔杩為�氭�ф祴璇曘�佺粨鏋勫寲 Schema 棰勮鍜屾寜杈撳叆鍙傛暟鑷姩鐢熸垚娴嬭瘯琛ㄥ崟銆�
+ {translate("ai.mcp.tools.description")}
</Typography>
</Box>
</AccordionSummary>
<AccordionDetails>
<Stack direction="row" justifyContent="space-between" alignItems="center" mb={1.5} flexWrap="wrap" useFlexGap>
<Button size="small" startIcon={<PreviewOutlinedIcon />} onClick={loadTools} disabled={loading}>
- 鍒锋柊宸ュ叿
+ {translate("ai.mcp.tools.refresh")}
</Button>
<Button
size="small"
@@ -267,7 +268,7 @@
onClick={handleConnectivityTest}
disabled={testingConnectivity}
>
- {testingConnectivity ? "娴嬭瘯涓�..." : "杩為�氭�ф祴璇�"}
+ {testingConnectivity ? translate("ai.common.testing") : translate("ai.mcp.list.connectivityTest")}
</Button>
</Stack>
{!!connectivity && (
@@ -289,7 +290,7 @@
</Alert>
)}
{!loading && !error && !tools.length && (
- <Alert severity="info">褰撳墠鎸傝浇鏈В鏋愬嚭浠讳綍宸ュ叿銆�</Alert>
+ <Alert severity="info">{translate("ai.mcp.tools.noTools")}</Alert>
)}
<Grid container spacing={2}>
{tools.map((tool) => {
@@ -303,11 +304,11 @@
<Box>
<Typography variant="subtitle1">{tool.name}</Typography>
<Typography variant="body2" color="text.secondary">
- {tool.description || "鏆傛棤鎻忚堪"}
+ {tool.description || translate("ai.common.none")}
</Typography>
{!!tool.toolPurpose && (
<Typography variant="caption" color="text.secondary" display="block" mt={0.5}>
- 鐢ㄩ��: {tool.toolPurpose}
+ {translate("ai.mcp.tools.purpose", { value: tool.toolPurpose })}
</Typography>
)}
</Box>
@@ -318,7 +319,7 @@
</Typography>
)}
<Typography variant="caption" color="text.secondary">
- {schemaInfo.fields.length} 涓弬鏁�
+ {translate("ai.mcp.tools.fieldCount", { count: schemaInfo.fields.length })}
</Typography>
<Typography variant="caption" color="text.secondary">
{tool.returnDirect ? "returnDirect" : "normal"}
@@ -331,13 +332,13 @@
<CardContent>
{!!tool.queryBoundary && (
<Alert severity="info" sx={{ mb: 2 }}>
- 鏌ヨ杈圭晫: {tool.queryBoundary}
+ {translate("ai.mcp.tools.queryBoundary", { value: tool.queryBoundary })}
</Alert>
)}
{!!tool.exampleQuestions?.length && (
<Alert severity="success" sx={{ mb: 2 }}>
<Typography variant="body2" fontWeight={700} mb={0.5}>
- 绀轰緥鎻愰棶
+ {translate("ai.mcp.tools.exampleQuestions")}
</Typography>
{tool.exampleQuestions.map((question) => (
<Typography key={question} variant="body2">
@@ -352,7 +353,7 @@
</Alert>
)}
<TextField
- label="鏍煎紡鍖� Input Schema"
+ label={translate("ai.mcp.tools.formattedSchema")}
value={schemaInfo.pretty || tool.inputSchema || ""}
fullWidth
multiline
@@ -391,7 +392,7 @@
</Grid>
)}
<TextField
- label="娴嬭瘯杈撳叆 JSON"
+ label={translate("ai.mcp.tools.testInput")}
value={inputs[tool.name] || ""}
onChange={(event) => handleInputChange(tool.name, event.target.value)}
fullWidth
@@ -399,7 +400,7 @@
minRows={5}
maxRows={12}
sx={{ mt: 2 }}
- placeholder='渚嬪锛歿"code":"A01"}'
+ placeholder={translate("ai.mcp.tools.testInputPlaceholder")}
/>
<Stack direction="row" justifyContent="flex-end" mt={1.5}>
<Button
@@ -408,11 +409,11 @@
onClick={() => handleTest(tool.name)}
disabled={testingToolName === tool.name}
>
- {testingToolName === tool.name ? "娴嬭瘯涓�..." : "鎵ц娴嬭瘯"}
+ {testingToolName === tool.name ? translate("ai.common.testing") : translate("ai.mcp.tools.executeTest")}
</Button>
</Stack>
<TextField
- label="娴嬭瘯缁撴灉"
+ label={translate("ai.mcp.tools.testResult")}
value={outputs[tool.name] || ""}
fullWidth
multiline
--
Gitblit v1.9.1