-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlanguage.js
More file actions
264 lines (233 loc) · 9.78 KB
/
language.js
File metadata and controls
264 lines (233 loc) · 9.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/**
* 语言配置文件
* Language configuration file
*/
var LANGUAGE = {
'en': {
// 导航栏
'app_title': 'Dot Matrix Tool',
'draw_instruction': 'Left mouse button to draw. Right mouse button (or Ctrl+Left) to erase.',
// 按钮
'generate': 'Generate',
'clear': 'Clear',
'save': 'Save',
'load': 'Load',
'import': 'Import',
'text_input': 'Text Input',
'export_json': 'Export JSON',
'export_code': 'Export Code',
// 下拉菜单
'byte_order': 'Byte Order',
'byte_order_row': 'Byte Order: Row Major',
'byte_order_column': 'Byte Order: Column Major',
'byte_order_column_row': 'Byte Order: Column + Row',
'big_endian': 'Big Endian',
'little_endian': 'Little Endian',
// 尺寸控制
'width': 'Width',
'height': 'Height',
// 文本输入对话框
'text_input_title': 'Text Input',
'input_text': 'Input Text:',
'font_size': 'Font Size:',
'alignment': 'Alignment',
'align_left': 'Left',
'align_center': 'Center',
'align_right': 'Right',
'alignment_desc': 'Controls the horizontal alignment of text in the dot matrix: left, center, or right',
'x_position': 'X Position (Horizontal):',
'y_position': 'Y Position (Vertical):',
'x_position_desc': 'Horizontal starting position of text in the grid',
'y_position_desc': 'Vertical starting position of text in the grid',
'merge': 'Merge with existing content',
'merge_desc': 'When checked, text will be merged with existing content; when unchecked, it will replace existing content',
'preview': 'Preview:',
'empty_preview': 'Please enter text',
'loading_font': 'Loading font...',
'cancel': 'Cancel',
'apply': 'Apply',
// 系统字体/来源 新增
'font_source': 'Font Source:',
'embedded_bitmap_font': 'Embedded bitmap font',
'system_font': 'System font',
'system_font_label': 'Font:',
'system_font_hint': 'Choose a font installed on your system (falls back if unavailable)',
'system_font_custom_label': 'Custom font family (optional):',
'system_font_custom_ph': "e.g., 'Courier New', 'SimSun', 'Microsoft YaHei'",
'system_font_custom_hint': 'Leave empty to use the selection above',
'system_font_size_label': 'Size (px):',
'system_font_threshold_label': 'Threshold (0-255):',
'system_font_threshold_hint': 'Smaller = bolder, Larger = thinner',
// 错误消息
'no_text': 'Please enter text!',
'font_not_loaded': 'Font not loaded yet, please try again later!',
'render_failed': 'Text rendering failed!',
'no_export_data': 'No data to export!',
'export_failed': 'Export failed: ',
'no_code': 'No code to export!'
},
'zh': {
// 导航栏
'app_title': '点阵工具',
'draw_instruction': '左键绘制,右键(或Ctrl+左键)擦除。',
// 按钮
'generate': '生成代码',
'clear': '清除',
'save': '保存',
'load': '加载',
'import': '导入',
'text_input': '文本输入',
'export_json': '导出JSON',
'export_code': '导出代码',
// 下拉菜单
'byte_order': '字节顺序',
'byte_order_row': '字节顺序: 行优先',
'byte_order_column': '字节顺序: 列优先',
'byte_order_column_row': '字节顺序: 列+行',
'big_endian': '大端序',
'little_endian': '小端序',
// 尺寸控制
'width': '宽度',
'height': '高度',
// 文本输入对话框
'text_input_title': '文本输入',
'input_text': '输入文本:',
'font_size': '字体大小:',
'alignment': '对齐方式',
'align_left': '左对齐',
'align_center': '居中对齐',
'align_right': '右对齐',
'alignment_desc': '控制文本在点阵中的水平对齐方式:左侧对齐、居中对齐或右侧对齐',
'x_position': 'X位置 (水平偏移):',
'y_position': 'Y位置 (垂直偏移):',
'x_position_desc': '文本在网格中的水平起始位置',
'y_position_desc': '文本在网格中的垂直起始位置',
'merge': '与现有内容合并',
'merge_desc': '勾选时文本会与网格中现有内容合并,取消勾选时会替换现有内容',
'preview': '预览:',
'empty_preview': '请输入文本',
'loading_font': '加载字体中...',
'cancel': '取消',
'apply': '应用',
// 系统字体/来源 新增
'font_source': '字体来源:',
'embedded_bitmap_font': '内置位图字体',
'system_font': '系统字体',
'system_font_label': '字体:',
'system_font_hint': '选择系统中已安装的字体(不存在将回退)',
'system_font_custom_label': '自定义字体族(可选):',
'system_font_custom_ph': "例如: 'Courier New', 'SimSun', 'Microsoft YaHei'",
'system_font_custom_hint': '留空则使用上面的选择项',
'system_font_size_label': '字号(px):',
'system_font_threshold_label': '阈值(0-255):',
'system_font_threshold_hint': '越小越粗,越大越细',
// 错误消息
'no_text': '请输入文本!',
'font_not_loaded': '字体尚未加载完成,请稍后再试!',
'render_failed': '文本渲染失败!',
'no_export_data': '没有可导出的数据!',
'export_failed': '导出失败: ',
'no_code': '没有可导出的代码!'
}
};
// 默认语言
var currentLanguage = 'en';
// 语言切换函数
function switchLanguage(lang) {
if (LANGUAGE[lang]) {
currentLanguage = lang;
updateUILanguage();
return true;
}
return false;
}
// 获取翻译文本
function getText(key) {
if (LANGUAGE[currentLanguage] && LANGUAGE[currentLanguage][key]) {
return LANGUAGE[currentLanguage][key];
}
// 如果找不到翻译,返回英文版本
return LANGUAGE['en'][key] || key;
}
// 更新UI语言
function updateUILanguage() {
// 更新导航栏
$('.navbar-brand').text(getText('app_title'));
$('.text-muted').first().text(getText('draw_instruction'));
// 更新按钮
$('#generateButton').text(getText('generate'));
$('#clearButton').text(getText('clear'));
$('#saveButton').text(getText('save'));
// 修复:input位于label内部,不能用prev()。更新label的第一个文本节点
(function() {
var $label = $('#loadInput').closest('label');
if ($label.length) {
var nodes = $label.contents();
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].nodeType === 3) { // 文本节点
nodes[i].nodeValue = getText('load') + ' ';
break;
}
}
}
})();
$('#importButton').text(getText('import'));
$('#textInputButton').text(getText('text_input'));
$('#exportJsonButton').text(getText('export_json'));
$('#exportCodeButton').text(getText('export_code'));
// 更新下拉菜单
$('#byteDrop').html(getText('byte_order_column_row') + ' <span class="caret"></span>');
$('#byteDropDiv .dropdown-item').eq(0).text(getText('byte_order_row'));
$('#byteDropDiv .dropdown-item').eq(1).text(getText('byte_order_column'));
$('#byteDropDiv .dropdown-item').eq(2).text(getText('byte_order_column_row'));
$('#endianDrop').html(getText('big_endian') + ' <span class="caret"></span>');
$('#endianDropDiv .dropdown-item').eq(0).text(getText('big_endian'));
$('#endianDropDiv .dropdown-item').eq(1).text(getText('little_endian'));
// 更新尺寸控制
$('label[for="widthInput"]').text(getText('width') + ':');
$('label[for="heightInput"]').text(getText('height') + ':');
// 更新文本输入对话框
$('#textInputModalLabel').text(getText('text_input_title'));
$('label[for="textInputArea"]').text(getText('input_text'));
$('label[for="fontSizeSelect"]').text(getText('font_size'));
$('#textInputModal .form-group').eq(2).find('label').first().text(getText('alignment') + ':');
$('label[for="alignLeft"]').text(getText('align_left') + ' (Left)');
$('label[for="alignCenter"]').text(getText('align_center') + ' (Center)');
$('label[for="alignRight"]').text(getText('align_right') + ' (Right)');
$('#textInputModal .form-group').eq(2).find('small').text(getText('alignment_desc'));
// 新增:系统字体/来源的国际化
$('#labelFontSource').text(getText('font_source'));
$('label[for="sourceEmbedded"]').text(getText('embedded_bitmap_font'));
$('label[for="sourceSystem"]').text(getText('system_font'));
$('label[for="systemFontFamily"]').text(getText('system_font_label'));
$('#hintSystemFontFamily').text(getText('system_font_hint'));
$('label[for="systemFontCustom"]').text(getText('system_font_custom_label'));
$('#systemFontCustom').attr('placeholder', getText('system_font_custom_ph'));
$('#hintSystemFontCustom').text(getText('system_font_custom_hint'));
$('label[for="systemFontSize"]').text(getText('system_font_size_label'));
$('label[for="systemFontThreshold"]').text(getText('system_font_threshold_label'));
$('#hintSystemFontThreshold').text(getText('system_font_threshold_hint'));
$('label[for="textOffsetX"]').text(getText('x_position'));
$('label[for="textOffsetY"]').text(getText('y_position'));
$('#textPositionControls').find('small').eq(0).text(getText('x_position_desc'));
$('#textPositionControls').find('small').eq(1).text(getText('y_position_desc'));
$('label[for="mergeWithExisting"]').text(getText('merge'));
$('#mergeWithExisting').parent().next('small').text(getText('merge_desc'));
$('#textInputModal .form-group').last().find('label').text(getText('preview') + ':');
$('.modal-footer .btn-secondary').text(getText('cancel'));
$('#applyTextButton').text(getText('apply'));
// 合并/替换提示国际化
$('#labelMerge').text(getText('merge'));
$('#hintMerge').text(getText('merge_desc'));
}
// 初始化语言切换按钮
$(function() {
$('#langEn').click(function() {
switchLanguage('en');
});
$('#langZh').click(function() {
switchLanguage('zh');
});
// 初始化UI语言
updateUILanguage();
});