Skip to content

Commit 912db63

Browse files
authored
[elsa] 编排页面中工具条的按钮增加说明 (#101)
1 parent f827419 commit 912db63

File tree

7 files changed

+76
-11
lines changed

7 files changed

+76
-11
lines changed

framework/elsa/fit-elsa-react/src/i18n.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,25 @@ import i18n from 'i18next';
88
import {initReactI18next} from 'react-i18next';
99
import en from './en_US.json';
1010
import zh from './zh_CN.json';
11+
import coreEn from '@fit-elsa/elsa-core/locales/en.json';
12+
import coreZh from '@fit-elsa/elsa-core/locales/zh.json';
13+
14+
const mergeTranslations = (local, core) => {
15+
return { ...core, ...local }; // core 的翻译作为基础,本地翻译优先级更高
16+
};
1117

1218
const resources = {
1319
en: {
14-
translation: en,
20+
translation: mergeTranslations(en, coreEn),
1521
},
1622
zh: {
17-
translation: zh,
23+
translation: mergeTranslations(zh, coreZh),
1824
},
1925
};
2026

2127
i18n.use(initReactI18next).init({
2228
resources,
23-
fallbackLng: 'zh-cn',
29+
fallbackLng: 'zh',
2430
interpolation: {
2531
escapeValue: false,
2632
},

framework/elsa/fit-elsa/core/defaultGraph.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import ElsaEditor from '../editor/default/elsa-editor.js';
99
import {EVENT_TYPE} from '../common/const.js';
1010
import {elsaCKEditor} from '../editor/default/elsaCKEditor.js';
1111
import {editorCommand} from './commands.js';
12+
import i18n from '../i18n/i18n.js';
1213

1314
/**
1415
* @inheritDoc
1516
*/
1617
const defaultGraph = (div, title) => {
1718
const self = graph(div, title);
19+
self.i18n = i18n;
1820

1921
self.editor = null;
2022
const initialize = self.initialize;

framework/elsa/fit-elsa/core/drawers/interactDrawer.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,13 @@ const interactDrawer = (graph, page, div) => {
9393
* @param {string} options.icon SVG 图标。
9494
* @param {string} options.className CSS 类名。
9595
* @param {Function} [options.onClick] 点击事件回调。
96+
* @param {string} [options.tooltip] 工具说明。
9697
* @returns {{ getComponent: Function, update: Function }}
9798
*/
98-
const createBaseTool = ({icon, className, onClick}) => {
99+
const createBaseTool = ({icon, className, onClick, tooltip}) => {
99100
const button = graph.createDom('div', 'div', className, page.id);
100101
button.innerHTML = icon;
102+
button.title = tooltip;
101103
Object.assign(button.style, {
102104
display: 'flex',
103105
width: '22px',
@@ -134,6 +136,7 @@ const interactDrawer = (graph, page, div) => {
134136
page.fitScreen(PAGE_FIT_SCREEN_SCALE_MIN, PAGE_FIT_SCREEN_SCALE_MAX);
135137
e.stopPropagation();
136138
},
139+
tooltip: graph.i18n.t('displayAllNodes'),
137140
});
138141
};
139142

@@ -151,6 +154,7 @@ const interactDrawer = (graph, page, div) => {
151154
tool.update(); // 触发更新
152155
e.stopPropagation();
153156
},
157+
tooltip: graph.i18n.t('handMode'),
154158
});
155159

156160
/**
@@ -178,6 +182,7 @@ const interactDrawer = (graph, page, div) => {
178182
page.reorganizeNodes(PAGE_REORGANIZE_SCREEN_SCALE);
179183
e.stopPropagation() // 阻止事件冒泡
180184
},
185+
tooltip: graph.i18n.t('reorganizeNodes'),
181186
});
182187
};
183188

@@ -189,7 +194,7 @@ const interactDrawer = (graph, page, div) => {
189194
const zoomTool = () => {
190195
const me = {};
191196

192-
const createZoomIn = () => {
197+
const createZoomOut = () => {
193198
const button = graph.createDom(div, 'div', 'barToolsZoomIn', page.id);
194199
button.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 16 16"><path fill="#1D1C23" fill-opacity="0.8" d="M1.333 8c0-.368.299-.666.667-.666h12a.667.667 0 1 1 0 1.333H2a.667.667 0 0 1-.667-.666Z"></path></svg>`;
195200
button.style.display = 'flex';
@@ -201,6 +206,7 @@ const interactDrawer = (graph, page, div) => {
201206
button.onclick = () => {
202207
me.zoomTo(page.scaleX - 0.1);
203208
};
209+
button.title = graph.i18n.t('zoomOut');
204210
return button;
205211
};
206212

@@ -234,7 +240,7 @@ const interactDrawer = (graph, page, div) => {
234240
return button;
235241
};
236242

237-
const createZoomOut = () => {
243+
const createZoomIn = () => {
238244
const button = graph.createDom(div, 'div', 'barToolsZoomOut', page.id);
239245
button.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 16 16" style="align-items: center;"><path fill="#1D1C23" fill-opacity="0.8" d="M8 1.334a.667.667 0 0 0-.667.667v5.333H2a.667.667 0 0 0 0 1.333h5.333v5.334a.667.667 0 0 0 1.334 0V8.667H14a.667.667 0 1 0 0-1.333H8.667V2.001A.667.667 0 0 0 8 1.334Z"></path></svg>`;
240246
button.style.display = 'flex';
@@ -246,6 +252,7 @@ const interactDrawer = (graph, page, div) => {
246252
button.onclick = () => {
247253
me.zoomTo(page.scaleX + 0.1);
248254
};
255+
button.title = graph.i18n.t('zoomIn');
249256
return button;
250257
};
251258

@@ -255,15 +262,15 @@ const interactDrawer = (graph, page, div) => {
255262
zoomWrapper.style.width = 'fit-content';
256263
zoomWrapper.style.height = 'fit-content';
257264

258-
const zoomIn = createZoomIn();
265+
const zoomOut = createZoomOut();
259266
const zoomSlider = createZoomSlider();
260267
const zoomText = createZoomText();
261-
const zoomOut = createZoomOut();
268+
const zoomIn = createZoomIn();
262269

263-
zoomWrapper.appendChild(zoomIn);
270+
zoomWrapper.appendChild(zoomOut);
264271
zoomWrapper.appendChild(zoomSlider);
265272
zoomWrapper.appendChild(zoomText);
266-
zoomWrapper.appendChild(zoomOut);
273+
zoomWrapper.appendChild(zoomIn);
267274

268275
/**
269276
* 获取缩放工具组件
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"displayAllNodes": "Display all nodes",
3+
"handMode": "Hand mode",
4+
"reorganizeNodes": "Organize nodes",
5+
"zoomOut": "Zoom Out",
6+
"zoomIn": "Zoom In"
7+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved.
3+
* This file is a part of the ModelEngine Project.
4+
* Licensed under the MIT License. See License.txt in the project root for license information.
5+
*--------------------------------------------------------------------------------------------*/
6+
7+
import i18n from 'i18next';
8+
import en from './en.json';
9+
import zh from './zh.json';
10+
11+
const resources = {
12+
en: {
13+
translation: en,
14+
},
15+
zh: {
16+
translation: zh,
17+
},
18+
};
19+
20+
i18n.init({
21+
resources,
22+
lng: 'zh',
23+
fallbackLng: 'zh',
24+
interpolation: {
25+
escapeValue: false,
26+
},
27+
returnNull: false,
28+
});
29+
30+
export default i18n;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"displayAllNodes": "显示所有节点",
3+
"handMode": "手模式",
4+
"reorganizeNodes": "整理节点",
5+
"zoomOut": "缩小",
6+
"zoomIn": "放大"
7+
}

framework/elsa/fit-elsa/package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"testEnvironment": "jsdom"
2828
},
2929
"dependencies": {
30-
"@dagrejs/dagre": "^1.1.4"
30+
"@dagrejs/dagre": "^1.1.4",
31+
"i18next": "^21.6.0"
3132
},
3233
"devDependencies": {
3334
"@babel/core": "^7.23.0",
@@ -47,5 +48,10 @@
4748
"video.js": "^8.9.0",
4849
"webpack": "5.94.0",
4950
"webpack-cli": "5.1.4"
51+
},
52+
"exports": {
53+
".": "./build/elsa.js",
54+
"./locales/en.json": "./i18n/en.json",
55+
"./locales/zh.json": "./i18n/zh.json"
5056
}
5157
}

0 commit comments

Comments
 (0)