Copilot commented on code in PR #702:
URL: https://github.com/apache/shenyu-dashboard/pull/702#discussion_r4229387836


##########
src/components/Exception/typeConfig.js:
##########
@@ -15,22 +15,24 @@
  * limitations under the License.
  */
 
-const config = {
+import { getIntlContent } from "../../utils/IntlUtils";
+
+const getTypeConfig = () => ({
   403: {
     img: "https://gw.alipayobjects.com/zos/rmsportal/wZcnGqRDyhPOEYFcZDnb.svg";,
     title: "403",
-    desc: "抱歉,你无权访问该页面",
+    desc: getIntlContent("SHENYU.EXCEPTION.403.DESC"),
   },
   404: {
     img: "https://gw.alipayobjects.com/zos/rmsportal/KpnpchXsobRgLElEozzI.svg";,
     title: "404",
-    desc: "抱歉,你访问的页面不存在",
+    desc: getIntlContent("SHENYU.EXCEPTION.404.DESC"),
   },
   500: {
     img: "https://gw.alipayobjects.com/zos/rmsportal/RVRUAYdCGeYNBWoKiIwB.svg";,
     title: "500",
-    desc: "抱歉,服务器出错了",
+    desc: getIntlContent("SHENYU.EXCEPTION.500.DESC"),
   },
-};
+});
 
-export default config;
+export default getTypeConfig;

Review Comment:
   This changes the module’s default export from a config object to a function, 
which is a breaking change for any existing imports that expect an object. If 
other modules import this file directly, consider preserving compatibility by 
keeping the original export shape (or exporting both an object-like API and the 
new getter), while still ensuring i18n strings resolve at render time.



##########
src/routes/Plugin/McpServer/ToolsModal.js:
##########
@@ -413,19 +413,23 @@ class AddModal extends Component {
       if (depth > MAX_NESTING_DEPTH) {
         message.destroy();
         message.error(
-          `参数嵌套深度超过限制(最大${MAX_NESTING_DEPTH}层): ${path}`,
+          
`${getIntlContent("SHENYU.MCP.TOOLS.PARAM.DEPTH.EXCEEDED")}${getIntlContent("SHENYU.MCP.TOOLS.PARAM.DEPTH.MAX.PREFIX")}${MAX_NESTING_DEPTH}${getIntlContent("SHENYU.MCP.TOOLS.PARAM.DEPTH.MAX.SUFFIX")}:
 ${path}`,
         );
         return false;
       }
 
       for (let i = 0; i < params.length; i += 1) {
         const item = params[i];
         const { type, name } = item;
-        const currentPath = path ? `${path}[${i}]` : `第${i + 1}行`;
+        const currentPath = path
+          ? `${path}[${i}]`
+          : `${getIntlContent("SHENYU.MCP.TOOLS.PARAM.ROW.PREFIX")}${i + 
1}${getIntlContent("SHENYU.MCP.TOOLS.PARAM.ROW.SUFFIX")}`;
 
         if (!type || !name) {
           message.destroy();
-          message.error(`${currentPath} 参数不完整,请填写名称、类型`);
+          message.error(
+            `${currentPath} 
${getIntlContent("SHENYU.MCP.TOOLS.PARAM.INCOMPLETE")}`,
+          );

Review Comment:
   These messages are now composed from many concatenated fragments, which is 
hard to read and easy to regress (missing punctuation/spaces, duplicated key 
usage, etc.). Consider extracting small helpers (e.g., 
formatMaxDepth(MAX_NESTING_DEPTH), formatRowLabel(i+1), 
formatDepthExceeded(path)) so the i18n composition is centralized and each call 
site stays readable.



##########
src/routes/Plugin/McpServer/ToolsModal.js:
##########
@@ -413,19 +413,23 @@ class AddModal extends Component {
       if (depth > MAX_NESTING_DEPTH) {
         message.destroy();
         message.error(
-          `参数嵌套深度超过限制(最大${MAX_NESTING_DEPTH}层): ${path}`,
+          
`${getIntlContent("SHENYU.MCP.TOOLS.PARAM.DEPTH.EXCEEDED")}${getIntlContent("SHENYU.MCP.TOOLS.PARAM.DEPTH.MAX.PREFIX")}${MAX_NESTING_DEPTH}${getIntlContent("SHENYU.MCP.TOOLS.PARAM.DEPTH.MAX.SUFFIX")}:
 ${path}`,

Review Comment:
   These messages are now composed from many concatenated fragments, which is 
hard to read and easy to regress (missing punctuation/spaces, duplicated key 
usage, etc.). Consider extracting small helpers (e.g., 
formatMaxDepth(MAX_NESTING_DEPTH), formatRowLabel(i+1), 
formatDepthExceeded(path)) so the i18n composition is centralized and each call 
site stays readable.



##########
src/routes/Plugin/McpServer/ToolsModal.js:
##########
@@ -413,19 +413,23 @@ class AddModal extends Component {
       if (depth > MAX_NESTING_DEPTH) {
         message.destroy();
         message.error(
-          `参数嵌套深度超过限制(最大${MAX_NESTING_DEPTH}层): ${path}`,
+          
`${getIntlContent("SHENYU.MCP.TOOLS.PARAM.DEPTH.EXCEEDED")}${getIntlContent("SHENYU.MCP.TOOLS.PARAM.DEPTH.MAX.PREFIX")}${MAX_NESTING_DEPTH}${getIntlContent("SHENYU.MCP.TOOLS.PARAM.DEPTH.MAX.SUFFIX")}:
 ${path}`,
         );
         return false;
       }
 
       for (let i = 0; i < params.length; i += 1) {
         const item = params[i];
         const { type, name } = item;
-        const currentPath = path ? `${path}[${i}]` : `第${i + 1}行`;
+        const currentPath = path
+          ? `${path}[${i}]`
+          : `${getIntlContent("SHENYU.MCP.TOOLS.PARAM.ROW.PREFIX")}${i + 
1}${getIntlContent("SHENYU.MCP.TOOLS.PARAM.ROW.SUFFIX")}`;

Review Comment:
   These messages are now composed from many concatenated fragments, which is 
hard to read and easy to regress (missing punctuation/spaces, duplicated key 
usage, etc.). Consider extracting small helpers (e.g., 
formatMaxDepth(MAX_NESTING_DEPTH), formatRowLabel(i+1), 
formatDepthExceeded(path)) so the i18n composition is centralized and each call 
site stays readable.



##########
src/routes/Plugin/McpServer/ToolsModal.js:
##########
@@ -614,7 +618,7 @@ class AddModal extends Component {
     if (path.length >= MAX_NESTING_DEPTH) {
       message.destroy();
       message.warning(
-        `已达到最大嵌套深度限制(${MAX_NESTING_DEPTH}层),无法继续添加子参数`,
+        
`${getIntlContent("SHENYU.MCP.TOOLS.PARAM.DEPTH.MAX.REACHED")}${getIntlContent("SHENYU.MCP.TOOLS.PARAM.DEPTH.MAX.PREFIX")}${MAX_NESTING_DEPTH}${getIntlContent("SHENYU.MCP.TOOLS.PARAM.DEPTH.MAX.SUFFIX")}${getIntlContent("SHENYU.MCP.TOOLS.PARAM.DEPTH.MAX.CANNOT.ADD")}`,

Review Comment:
   These messages are now composed from many concatenated fragments, which is 
hard to read and easy to regress (missing punctuation/spaces, duplicated key 
usage, etc.). Consider extracting small helpers (e.g., 
formatMaxDepth(MAX_NESTING_DEPTH), formatRowLabel(i+1), 
formatDepthExceeded(path)) so the i18n composition is centralized and each call 
site stays readable.



##########
src/utils/request.js:
##########
@@ -20,31 +20,34 @@ import { notification } from "antd";
 import store from "../index";
 import { getIntlContent } from "./IntlUtils";
 
-const codeMessage = {
-  200: "服务器成功返回请求的数据。",
-  201: "新建或修改数据成功。",
-  202: "一个请求已经进入后台排队(异步任务)。",
-  204: "删除数据成功。",
-  400: "发出的请求有错误,服务器没有进行新建或修改数据的操作。",
-  401: "用户没有权限(令牌、用户名、密码错误)。",
-  403: "用户得到授权,但是访问是被禁止的。",
-  404: "发出的请求针对的是不存在的记录,服务器没有进行操作。",
-  406: "请求的格式不可得。",
-  410: "请求的资源被永久删除,且不会再得到的。",
-  422: "当创建一个对象时,发生一个验证错误。",
-  500: "服务器发生错误,请检查服务器。",
-  502: "网关错误。",
-  503: "服务不可用,服务器暂时过载或维护。",
-  504: "网关超时。",
+const getCodeMessage = (status) => {
+  const codeMessage = {
+    200: getIntlContent("SHENYU.REQUEST.STATUS.200"),
+    201: getIntlContent("SHENYU.REQUEST.STATUS.201"),
+    202: getIntlContent("SHENYU.REQUEST.STATUS.202"),
+    204: getIntlContent("SHENYU.REQUEST.STATUS.204"),
+    400: getIntlContent("SHENYU.REQUEST.STATUS.400"),
+    401: getIntlContent("SHENYU.REQUEST.STATUS.401"),
+    403: getIntlContent("SHENYU.REQUEST.STATUS.403"),
+    404: getIntlContent("SHENYU.REQUEST.STATUS.404"),
+    406: getIntlContent("SHENYU.REQUEST.STATUS.406"),
+    410: getIntlContent("SHENYU.REQUEST.STATUS.410"),
+    422: getIntlContent("SHENYU.REQUEST.STATUS.422"),
+    500: getIntlContent("SHENYU.REQUEST.STATUS.500"),
+    502: getIntlContent("SHENYU.REQUEST.STATUS.502"),
+    503: getIntlContent("SHENYU.REQUEST.STATUS.503"),
+    504: getIntlContent("SHENYU.REQUEST.STATUS.504"),
+  };
+  return codeMessage[status];
 };
 
 function checkStatus(response) {
   if (response.status >= 200 && response.status < 300) {
     return response;
   }
-  const errortext = codeMessage[response.status] || response.statusText;
+  const errortext = getCodeMessage(response.status) || response.statusText;

Review Comment:
   getCodeMessage() allocates a new object and performs 14 getIntlContent() 
calls on every non-2xx response. To keep locale-switch correctness while 
avoiding repeated allocations, consider defining a constant status->key map (or 
switch) once (e.g., outside the function) and only calling getIntlContent() for 
the single matched key at runtime.



##########
src/utils/request.js:
##########
@@ -20,31 +20,34 @@ import { notification } from "antd";
 import store from "../index";
 import { getIntlContent } from "./IntlUtils";
 
-const codeMessage = {
-  200: "服务器成功返回请求的数据。",
-  201: "新建或修改数据成功。",
-  202: "一个请求已经进入后台排队(异步任务)。",
-  204: "删除数据成功。",
-  400: "发出的请求有错误,服务器没有进行新建或修改数据的操作。",
-  401: "用户没有权限(令牌、用户名、密码错误)。",
-  403: "用户得到授权,但是访问是被禁止的。",
-  404: "发出的请求针对的是不存在的记录,服务器没有进行操作。",
-  406: "请求的格式不可得。",
-  410: "请求的资源被永久删除,且不会再得到的。",
-  422: "当创建一个对象时,发生一个验证错误。",
-  500: "服务器发生错误,请检查服务器。",
-  502: "网关错误。",
-  503: "服务不可用,服务器暂时过载或维护。",
-  504: "网关超时。",
+const getCodeMessage = (status) => {
+  const codeMessage = {
+    200: getIntlContent("SHENYU.REQUEST.STATUS.200"),
+    201: getIntlContent("SHENYU.REQUEST.STATUS.201"),
+    202: getIntlContent("SHENYU.REQUEST.STATUS.202"),
+    204: getIntlContent("SHENYU.REQUEST.STATUS.204"),
+    400: getIntlContent("SHENYU.REQUEST.STATUS.400"),
+    401: getIntlContent("SHENYU.REQUEST.STATUS.401"),
+    403: getIntlContent("SHENYU.REQUEST.STATUS.403"),
+    404: getIntlContent("SHENYU.REQUEST.STATUS.404"),
+    406: getIntlContent("SHENYU.REQUEST.STATUS.406"),
+    410: getIntlContent("SHENYU.REQUEST.STATUS.410"),
+    422: getIntlContent("SHENYU.REQUEST.STATUS.422"),
+    500: getIntlContent("SHENYU.REQUEST.STATUS.500"),
+    502: getIntlContent("SHENYU.REQUEST.STATUS.502"),
+    503: getIntlContent("SHENYU.REQUEST.STATUS.503"),
+    504: getIntlContent("SHENYU.REQUEST.STATUS.504"),
+  };
+  return codeMessage[status];

Review Comment:
   getCodeMessage() allocates a new object and performs 14 getIntlContent() 
calls on every non-2xx response. To keep locale-switch correctness while 
avoiding repeated allocations, consider defining a constant status->key map (or 
switch) once (e.g., outside the function) and only calling getIntlContent() for 
the single matched key at runtime.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to