初始化后,引入汉化文件 ,注意引入顺序
<link rel="stylesheet" href="bpmn/css/bpmn.css" />
<link rel="stylesheet" href="bpmn/css/diagram-js.css" />
<script type="text/javascript" src="../js/jquery.js" ></script>
<script src="bpmn/bpmn-modeler.development.js"></script>
//汉化
<script type="text/javascript" src="bpmn/sinicization/customTranslate.js" ></script>
初始化
$(function(){
var BpmnModeler = window.BpmnJS;
//此处为汉化对象
var customTranslateModule = {
translate: [ 'value', customTranslate]
};
var xml = "<?xml version='1.0' encoding='UTF-8'?><definitions xmlns='http://www.omg.org/spec/BPMN/20100524/MODEL' xmlns:bpmndi='http://www.omg.org/spec/BPMN/20100524/DI' xmlns:omgdi='http://www.omg.org/spec/DD/20100524/DI' xmlns:omgdc='http://www.omg.org/spec/DD/20100524/DC' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' id='sid-38422fae-e03e-43a3-bef4-bd33b32041b2' targetNamespace='http://bpmn.io/bpmn' exporter='bpmn-js (https://demo.bpmn.io)' exporterVersion='5.1.2'><process id='Process_1' isExecutable='false'><startEvent id='StartEvent_1y45yut' name='开始'><outgoing>SequenceFlow_0h21x7r</outgoing></startEvent><task id='Task_1hcentk' name='审批'><incoming>SequenceFlow_0h21x7r</incoming><outgoing>SequenceFlow_06o0wf0</outgoing></task><sequenceFlow id='SequenceFlow_0h21x7r' sourceRef='StartEvent_1y45yut' targetRef='Task_1hcentk' /><task id='Task_13intos' fill='red' name='下一节点'><incoming>SequenceFlow_06o0wf0</incoming><outgoing>SequenceFlow_1oydyx4</outgoing></task><sequenceFlow id='SequenceFlow_06o0wf0' sourceRef='Task_1hcentk' targetRef='Task_13intos' /><endEvent id='EndEvent_0aot3cz' name='结束'><incoming>SequenceFlow_1oydyx4</incoming></endEvent><sequenceFlow id='SequenceFlow_1oydyx4' sourceRef='Task_13intos' targetRef='EndEvent_0aot3cz' /></process><bpmndi:BPMNDiagram id='BpmnDiagram_1'><bpmndi:BPMNPlane id='BpmnPlane_1' bpmnElement='Process_1'><bpmndi:BPMNShape id='StartEvent_1y45yut_di' bpmnElement='StartEvent_1y45yut'><omgdc:Bounds x='152' y='102' width='36' height='36' /><bpmndi:BPMNLabel><omgdc:Bounds x='160' y='145' width='22' height='14' /></bpmndi:BPMNLabel></bpmndi:BPMNShape><bpmndi:BPMNShape id='Task_1hcentk_di' bpmnElement='Task_1hcentk'><omgdc:Bounds x='240' y='80' width='100' height='80' /></bpmndi:BPMNShape><bpmndi:BPMNEdge id='SequenceFlow_0h21x7r_di' bpmnElement='SequenceFlow_0h21x7r'><omgdi:waypoint x='188' y='120' /><omgdi:waypoint x='240' y='120' /></bpmndi:BPMNEdge><bpmndi:BPMNShape id='Task_13intos_di' bpmnElement='Task_13intos'><omgdc:Bounds x='400' y='80' width='100' height='80' /></bpmndi:BPMNShape><bpmndi:BPMNEdge id='SequenceFlow_06o0wf0_di' bpmnElement='SequenceFlow_06o0wf0'><omgdi:waypoint x='340' y='120' /><omgdi:waypoint x='400' y='120' /></bpmndi:BPMNEdge><bpmndi:BPMNShape id='EndEvent_0aot3cz_di' bpmnElement='EndEvent_0aot3cz'><omgdc:Bounds x='562' y='102' width='36' height='36' /><bpmndi:BPMNLabel><omgdc:Bounds x='569' y='145' width='22' height='14' /></bpmndi:BPMNLabel></bpmndi:BPMNShape><bpmndi:BPMNEdge id='SequenceFlow_1oydyx4_di' bpmnElement='SequenceFlow_1oydyx4'><omgdi:waypoint x='500' y='120' /><omgdi:waypoint x='562' y='120' /></bpmndi:BPMNEdge></bpmndi:BPMNPlane></bpmndi:BPMNDiagram></definitions>"; // ADD BPMN 2.0 XML HERE
var modeler = new BpmnModeler({
container: '#canvas',
additionalModules:[
customTranslateModule
]
});
modeler.importXML(xml, function(err) {
if (err) {
console.log('error rendering', err);
} else {
console.log('rendered');
}
});
});
效果图预览
汉化文件 customTranslate.js
1 var customTranslate = function(template, replacements) {
2 replacements = replacements || {};
3
4 // Translate
5 template = translations[template] || template;
6
7 // Replace
8 return template.replace(/{([^}]+)}/g, function(_, key) {
9
10 let str=replacements[key];
11 if(translations[replacements[key]]!=null&&translations[replacements[key]]!='undefined'){
12 str=translations[replacements[key]];
13 }
14 return str || '{' + key + '}';
15
16 });
17 }
18 var translations = {
19 'Create StartEvent':'创建开始节点',
20 'Create EndEvent':'创建结束节点',
21 'Create user-task':'创建用户任务',
22 // Labels
23 'Activate the global connect tool' : '激活全局连接工具',
24 'Append {type}': '添加 {type}',
25 'Add Lane above': '在上面添加道',
26 'Divide into two Lanes': '分割成两个道',
27 'Divide into three Lanes': '分割成三个道',
28 'Add Lane below': '在下面添加道',
29 'Append compensation activity': '追加补偿活动',
30 'Change type': '修改类型',
31 'Connect using Association': '使用关联连接',
32 'Connect using Sequence/MessageFlow or Association': '使用顺序/消息流或者关联连接',
33 'Connect using DataInputAssociation': '使用数据输入关联连接',
34 'Remove': '移除',
35 'Activate the hand tool': '激活抓手工具',
36 'Activate the lasso tool': '激活套索工具',
37 'Activate the create/remove space tool': '激活创建/删除空间工具',
38 'Create expanded SubProcess': '创建扩展子过程',
39 'Create IntermediateThrowEvent/BoundaryEvent' : '创建中间抛出事件/边界事件',
40 'Create Pool/Participant': '创建池/参与者',
41 'Parallel Multi Instance': '并行多重事件',
42 'Sequential Multi Instance': '时序多重事件',
43 'DataObjectReference':'数据对象参考',
44 'DataStoreReference':'数据存储参考',
45 'Loop': '循环',
46 'Ad-hoc': '即席',
47 'Create {type}': '创建 {type}',
48 'Create Task': '任务',
49 'Send Task': '发送任务',
50 'Receive Task': '接收任务',
51 'User Task': '用户任务',
52 'Manual Task': '手工任务',
53 'Business Rule Task': '业务规则任务',
54 'Service Task': '服务任务',
55 'Script Task': '脚本任务',
56 'Call Activity': '调用活动',
57 'Sub Process (collapsed)': '子流程(折叠的)',
58 'Sub Process (expanded)': '子流程(展开的)',
59 'Start Event': '开始事件',
60 'StartEvent': '开始事件',
61 'Intermediate Throw Event': '中间事件',
62 'End Event': '结束事件',
63 'EndEvent': '结束事件',
64 'Create Gateway': '创建网关',
65 'Create Intermediate/Boundary Event': '创建中间/边界事件',
66 'Message Start Event': '消息开始事件',
67 'Timer Start Event': '定时开始事件',
68 'Conditional Start Event': '条件开始事件',
69 'Signal Start Event': '信号开始事件',
70 'Error Start Event': '错误开始事件',
71 'Escalation Start Event': '升级开始事件',
72 'Compensation Start Event': '补偿开始事件',
73 'Message Start Event (non-interrupting)': '消息开始事件(非中断)',
74 'Timer Start Event (non-interrupting)': '定时开始事件(非中断)',
75 'Conditional Start Event (non-interrupting)': '条件开始事件(非中断)',
76 'Signal Start Event (non-interrupting)': '信号开始事件(非中断)',
77 'Escalation Start Event (non-interrupting)': '升级开始事件(非中断)',
78 'Message Intermediate Catch Event': '消息中间捕获事件',
79 'Message Intermediate Throw Event': '消息中间抛出事件',
80 'Timer Intermediate Catch Event': '定时中间捕获事件',
81 'Escalation Intermediate Throw Event': '升级中间抛出事件',
82 'Conditional Intermediate Catch Event': '条件中间捕获事件',
83 'Link Intermediate Catch Event': '链接中间捕获事件',
84 'Link Intermediate Throw Event': '链接中间抛出事件',
85 'Compensation Intermediate Throw Event': '补偿中间抛出事件',
86 'Signal Intermediate Catch Event': '信号中间捕获事件',
87 'Signal Intermediate Throw Event': '信号中间抛出事件',
88 'Message End Event': '消息结束事件',
89 'Escalation End Event': '定时结束事件',
90 'Error End Event': '错误结束事件',
91 'Cancel End Event': '取消结束事件',
92 'Compensation End Event': '补偿结束事件',
93 'Signal End Event': '信号结束事件',
94 'Terminate End Event': '终止结束事件',
95 'Message Boundary Event': '消息边界事件',
96 'Message Boundary Event (non-interrupting)': '消息边界事件(非中断)',
97 'Timer Boundary Event': '定时边界事件',
98 'Timer Boundary Event (non-interrupting)': '定时边界事件(非中断)',
99 'Escalation Boundary Event': '升级边界事件',
100 'Escalation Boundary Event (non-interrupting)': '升级边界事件(非中断)',
101 'Conditional Boundary Event': '条件边界事件',
102 'Conditional Boundary Event (non-interrupting)': '条件边界事件(非中断)',
103 'Error Boundary Event': '错误边界事件',
104 'Cancel Boundary Event': '取消边界事件',
105 'Signal Boundary Event': '信号边界事件',
106 'Signal Boundary Event (non-interrupting)': '信号边界事件(非中断)',
107 'Compensation Boundary Event': '补偿边界事件',
108 'Exclusive Gateway': '互斥网关',
109 'Parallel Gateway': '并行网关',
110 'Inclusive Gateway': '相容网关',
111 'Complex Gateway': '复杂网关',
112 'Event based Gateway': '事件网关',
113 'Transaction': '转运',
114 'Sub Process': '子流程',
115 'Event Sub Process': '事件子流程',
116 'Collapsed Pool': '折叠池',
117 'Expanded Pool': '展开池',
118
119 // Errors
120 'no parent for {element} in {parent}': '在{parent}里,{element}没有父类',
121 'no shape type specified': '没有指定的形状类型',
122 'flow elements must be children of pools/participants': '流元素必须是池/参与者的子类',
123 'out of bounds release': 'out of bounds release',
124 'more than {count} child lanes': '子道大于{count} ',
125 'element required': '元素不能为空',
126 'diagram not part of bpmn:Definitions': '流程图不符合bpmn规范',
127 'no diagram to display': '没有可展示的流程图',
128 'no process or collaboration to display': '没有可展示的流程/协作',
129 'element {element} referenced by {referenced}#{property} not yet drawn': '由{referenced}#{property}引用的{element}元素仍未绘制',
130 'already rendered {element}': '{element} 已被渲染',
131 'failed to import {element}': '导入{element}失败',
132 //属性面板的参数
133 'Id':'id',
134 'Name':'name',
135 'General':'属性',
136 'Details':'详情',
137 'Message Name':'消息名称',
138 'Message':'消息',
139 'Initiator':'创建者',
140 'Asynchronous Continuations':'持续异步',
141 'Asynchronous Before':'异步前',
142 'Asynchronous After':'异步后',
143 'Job Configuration':'工作配置',
144 'Exclusive':'排除',
145 'Job Priority':'工作优先级',
146 'Retry Time Cycle':'重试时间周期',
147 'Documentation':'文档',
148 'Element Documentation':'元素文档',
149 'History Configuration':'历史配置',
150 'History Time To Live':'历史的生存时间',
151 'Forms':'表单',
152 'Form Key':'表单key',
153 'Form Fields':'表单字段',
154 'Business Key':'业务key',
155 'Form Field':'表单字段',
156 'ID':'编号',
157 'Type':'类型',
158 'Label':'名称',
159 'Default Value':'默认值',
160 'Validation':'校验',
161 'Add Constraint':'添加约束',
162 'Config':'配置',
163 'Properties':'属性',
164 'Add Property':'添加属性',
165 'Value':'值',
166 'Listeners':'监听器',
167 'Execution Listener':'执行监听',
168 'Event Type':'事件类型',
169 'Listener Type':'监听器类型',
170 'Java Class':'Java类',
171 'Expression':'表达式',
172 'Must provide a value':'必须提供一个值',
173 'Delegate Expression':'代理表达式',
174 'Script':'脚本',
175 'Script Format':'脚本格式',
176 'Script Type':'脚本类型',
177 'Inline Script':'内联脚本',
178 'External Script':'外部脚本',
179 'Resource':'资源',
180 'Field Injection':'字段注入',
181 'Extensions':'扩展',
182 'Input/Output':'输入/输出',
183 'Input Parameters':'输入参数',
184 'Output Parameters':'输出参数',
185 'Parameters':'参数',
186 'Output Parameter':'输出参数',
187 'Timer Definition Type':'定时器定义类型',
188 'Timer Definition':'定时器定义',
189 'Date':'日期',
190 'Duration':'持续',
191 'Cycle':'循环',
192 'Signal':'信号',
193 'Signal Name':'信号名称',
194 'Escalation':'升级',
195 'Error':'错误',
196 'Link Name':'链接名称',
197 'Condition':'条件名称',
198 'Variable Name':'变量名称',
199 'Variable Event':'变量事件',
200 'Specify more than one variable change event as a comma separated list.':'多个变量事件以逗号隔开',
201 'Wait for Completion':'等待完成',
202 'Activity Ref':'活动参考',
203 'Version Tag':'版本标签',
204 'Executable':'可执行文件',
205 'External Task Configuration':'扩展任务配置',
206 'Task Priority':'任务优先级',
207 'External':'外部',
208 'Connector':'连接器',
209 'Must configure Connector':'必须配置连接器',
210 'Connector Id':'连接器编号',
211 'Implementation':'实现方式',
212 'Field Injections':'字段注入',
213 'Fields':'字段',
214 'Result Variable':'结果变量',
215 'Topic':'主题',
216 'Configure Connector':'配置连接器',
217 'Input Parameter':'输入参数',
218 'Assignee':'代理人',
219 'Candidate Users':'候选用户',
220 'Candidate Groups':'候选组',
221 'Due Date':'到期时间',
222 'Follow Up Date':'跟踪日期',
223 'Priority':'优先级',
224 'This maps to the process definition key.':'此处定义工作流主键',
225 'The follow up date as an EL expression (e.g. ${someDate} or an ISO date (e.g. 2015-06-26T09:54:00)':'跟踪日期必须符合EL表达式,如: ${someDate} ,或者一个ISO标准日期,如:2015-06-26T09:54:00',
226 'The due date as an EL expression (e.g. ${someDate} or an ISO date (e.g. 2015-06-26T09:54:00)':'跟踪日期必须符合EL表达式,如: ${someDate} ,或者一个ISO标准日期,如:2015-06-26T09:54:00',
227 'Variables':'变量',
228
229
230 }