From b546cf3ad0e6bbb7a2f1d80a52fe3156506f7053 Mon Sep 17 00:00:00 2001 From: "Yoan.liu" Date: Tue, 20 May 2025 14:55:48 +0800 Subject: [PATCH] multi language support --- .../workflow/node/ConditionNode.tsx | 2 +- .../workflow/node/ConditionNodeConfigForm.tsx | 64 ++++++++++++------- .../i18n/locales/en/nls.workflow.nodes.json | 21 ++++++ .../i18n/locales/zh/nls.workflow.nodes.json | 21 ++++++ 4 files changed, 84 insertions(+), 24 deletions(-) diff --git a/ui/src/components/workflow/node/ConditionNode.tsx b/ui/src/components/workflow/node/ConditionNode.tsx index 60a35c26..43b32e60 100644 --- a/ui/src/components/workflow/node/ConditionNode.tsx +++ b/ui/src/components/workflow/node/ConditionNode.tsx @@ -5,7 +5,7 @@ import { Button, Card, Popover } from "antd"; import SharedNode, { type SharedNodeProps } from "./_SharedNode"; import AddNode from "./AddNode"; import ConditionNodeConfigForm, { ConditionItem, ConditionNodeConfigFormFieldValues, ConditionNodeConfigFormInstance } from "./ConditionNodeConfigForm"; -import { Expr, WorkflowNodeConfigForCondition, WorkflowNodeIoValueType } from "@/domain/workflow"; +import { Expr, WorkflowNodeIoValueType } from "@/domain/workflow"; import { produce } from "immer"; import { useWorkflowStore } from "@/stores/workflow"; import { useZustandShallowSelector } from "@/hooks"; diff --git a/ui/src/components/workflow/node/ConditionNodeConfigForm.tsx b/ui/src/components/workflow/node/ConditionNodeConfigForm.tsx index b041ea7c..f2d08253 100644 --- a/ui/src/components/workflow/node/ConditionNodeConfigForm.tsx +++ b/ui/src/components/workflow/node/ConditionNodeConfigForm.tsx @@ -1,6 +1,7 @@ import { forwardRef, memo, useEffect, useImperativeHandle, useState } from "react"; -import { Button, Card, Form, Input, Select, Space, Radio, DatePicker } from "antd"; +import { Button, Card, Form, Input, Select, Radio } from "antd"; import { PlusOutlined, DeleteOutlined } from "@ant-design/icons"; +import i18n from "@/i18n"; import { WorkflowNodeConfigForCondition, @@ -17,6 +18,7 @@ import { import { FormInstance } from "antd"; import { useZustandShallowSelector } from "@/hooks"; import { useWorkflowStore } from "@/stores/workflow"; +import { useTranslation } from "react-i18next"; // 表单内部使用的扁平结构 - 修改后只保留必要字段 export interface ConditionItem { @@ -98,15 +100,15 @@ const getOperatorsByType = (type: string): { value: ComparisonOperator; label: s case "number": case "string": return [ - { value: "==", label: "等于 (==)" }, - { value: "!=", label: "不等于 (!=)" }, - { value: ">", label: "大于 (>)" }, - { value: ">=", label: "大于等于 (>=)" }, - { value: "<", label: "小于 (<)" }, - { value: "<=", label: "小于等于 (<=)" }, + { value: "==", label: i18n.t("workflow_node.condition.form.comparison.equal") }, + { value: "!=", label: i18n.t("workflow_node.condition.form.comparison.not_equal") }, + { value: ">", label: i18n.t("workflow_node.condition.form.comparison.greater_than") }, + { value: ">=", label: i18n.t("workflow_node.condition.form.comparison.greater_than_or_equal") }, + { value: "<", label: i18n.t("workflow_node.condition.form.comparison.less_than") }, + { value: "<=", label: i18n.t("workflow_node.condition.form.comparison.less_than_or_equal") }, ]; case "boolean": - return [{ value: "is", label: "为" }]; + return [{ value: "is", label: i18n.t("workflow_node.condition.form.comparison.is") }]; default: return []; } @@ -126,6 +128,9 @@ const getVariableTypeFromSelector = (selector: string): string => { const ConditionNodeConfigForm = forwardRef( ({ className, style, disabled, initialValues, onValuesChange, nodeId }, ref) => { + const { t } = useTranslation(); + const prefix = "workflow_node.condition.form"; + const { getWorkflowOuptutBeforeId } = useWorkflowStore(useZustandShallowSelector(["updateNode", "getWorkflowOuptutBeforeId"])); const [form] = Form.useForm(); @@ -182,9 +187,14 @@ const ConditionNodeConfigForm = forwardRef
{/* 左侧变量选择器 */} - + ); @@ -223,18 +238,21 @@ const ConditionNodeConfigForm = forwardRef + {varType === "boolean" ? ( - + {t(`${prefix}.value.boolean.true`)} + {t(`${prefix}.value.boolean.false`)} ) : varType === "number" ? ( - - ) : varType === "date" ? ( - + ) : ( - + )} ); @@ -258,7 +276,7 @@ const ConditionNodeConfigForm = forwardRef} > - 添加条件 + {t(`${prefix}.add_condition.button`)} @@ -266,10 +284,10 @@ const ConditionNodeConfigForm = forwardRef {formModel.conditions && formModel.conditions.length > 1 && ( - + - 满足所有条件 (AND) - 满足任一条件 (OR) + {t(`${prefix}.logical_operator.and`)} + {t(`${prefix}.logical_operator.or`)} )} diff --git a/ui/src/i18n/locales/en/nls.workflow.nodes.json b/ui/src/i18n/locales/en/nls.workflow.nodes.json index 7b53e6e4..a0288838 100644 --- a/ui/src/i18n/locales/en/nls.workflow.nodes.json +++ b/ui/src/i18n/locales/en/nls.workflow.nodes.json @@ -790,6 +790,26 @@ "workflow_node.branch.label": "Parallel branch", "workflow_node.condition.label": "Branch", + "workflow_node.condition.form.variable.placeholder": "Please select variable", + "workflow_node.condition.form.variable.errmsg": "Please select variable", + "workflow_node.condition.form.operator.errmsg": "Please select operator", + "workflow_node.condition.form.value.errmsg": "Please enter value", + "workflow_node.condition.form.value.string.placeholder": "Please enter value", + "workflow_node.condition.form.value.number.placeholder": "Please enter value", + "workflow_node.condition.form.value.boolean.placeholder": "Please select value", + "workflow_node.condition.form.value.boolean.true": "True", + "workflow_node.condition.form.value.boolean.false": "False", + "workflow_node.condition.form.add_condition.button": "Add condition", + "workflow_node.condition.form.logical_operator.label": "Logical operator", + "workflow_node.condition.form.logical_operator.and": "Meet all conditions (AND)", + "workflow_node.condition.form.logical_operator.or": "Meet any condition (OR)", + "workflow_node.condition.form.comparison.equal": "Equal", + "workflow_node.condition.form.comparison.not_equal": "Not equal", + "workflow_node.condition.form.comparison.greater_than": "Greater than", + "workflow_node.condition.form.comparison.greater_than_or_equal": "Greater than or equal", + "workflow_node.condition.form.comparison.less_than": "Less than", + "workflow_node.condition.form.comparison.less_than_or_equal": "Less than or equal", + "workflow_node.condition.form.comparison.is": "Is", "workflow_node.execute_result_branch.label": "Execution result branch", @@ -797,3 +817,4 @@ "workflow_node.execute_failure.label": "If the previous node failed ..." } + diff --git a/ui/src/i18n/locales/zh/nls.workflow.nodes.json b/ui/src/i18n/locales/zh/nls.workflow.nodes.json index 89cbfc11..9381aa71 100644 --- a/ui/src/i18n/locales/zh/nls.workflow.nodes.json +++ b/ui/src/i18n/locales/zh/nls.workflow.nodes.json @@ -789,6 +789,26 @@ "workflow_node.branch.label": "并行分支", "workflow_node.condition.label": "分支", + "workflow_node.condition.form.variable.placeholder": "选择变量", + "workflow_node.condition.form.variable.errmsg": "请选择变量", + "workflow_node.condition.form.operator.errmsg": "请选择操作符", + "workflow_node.condition.form.value.errmsg": "请输入值", + "workflow_node.condition.form.value.string.placeholder": "输入值", + "workflow_node.condition.form.value.number.placeholder": "输入数值", + "workflow_node.condition.form.value.boolean.placeholder": "选择值", + "workflow_node.condition.form.value.boolean.true": "是", + "workflow_node.condition.form.value.boolean.false": "否", + "workflow_node.condition.form.add_condition.button": "添加条件", + "workflow_node.condition.form.logical_operator.label": "条件逻辑", + "workflow_node.condition.form.logical_operator.and": "满足所有条件 (AND)", + "workflow_node.condition.form.logical_operator.or": "满足任一条件 (OR)", + "workflow_node.condition.form.comparison.equal": "等于", + "workflow_node.condition.form.comparison.not_equal": "不等于", + "workflow_node.condition.form.comparison.greater_than": "大于", + "workflow_node.condition.form.comparison.greater_than_or_equal": "大于等于", + "workflow_node.condition.form.comparison.less_than": "小于", + "workflow_node.condition.form.comparison.less_than_or_equal": "小于等于", + "workflow_node.condition.form.comparison.is": "为", "workflow_node.execute_result_branch.label": "执行结果分支", @@ -796,3 +816,4 @@ "workflow_node.execute_failure.label": "若前序节点执行失败…" } +