-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Expand file tree
/
Copy pathlabel.ts
More file actions
382 lines (337 loc) · 12.5 KB
/
label.ts
File metadata and controls
382 lines (337 loc) · 12.5 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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/**
* 对于需要动态获取的翻译文本:
* 1. 储存 key -> i18n-key 的 keyMap
* 2. 通过函数翻译文本
*/
import { loggerService } from '@logger'
import type { AgentType, BuiltinMCPServerName, BuiltinOcrProviderId } from '@renderer/types'
import { BuiltinMCPServerNames } from '@renderer/types'
import i18n from './index'
const t = i18n.t
const logger = loggerService.withContext('i18n:label')
const getLabel = (keyMap: Record<string, string>, key: string, fallback?: string) => {
const result = keyMap[key]
if (result) {
return t(result)
} else {
logger.error(`Missing key ${key}`)
return fallback ?? key
}
}
const providerKeyMap = {
'302ai': 'provider.302ai',
aihubmix: 'provider.aihubmix',
alayanew: 'provider.alayanew',
anthropic: 'provider.anthropic',
'aws-bedrock': 'provider.aws-bedrock',
'azure-openai': 'provider.azure-openai',
baichuan: 'provider.baichuan',
'baidu-cloud': 'provider.baidu-cloud',
burncloud: 'provider.burncloud',
cephalon: 'provider.cephalon',
cherryin: 'provider.cherryin',
copilot: 'provider.copilot',
dashscope: 'provider.dashscope',
deepseek: 'provider.deepseek',
dmxapi: 'provider.dmxapi',
doubao: 'provider.doubao',
fireworks: 'provider.fireworks',
gemini: 'provider.gemini',
'gitee-ai': 'provider.gitee-ai',
github: 'provider.github',
gpustack: 'provider.gpustack',
grok: 'provider.grok',
groq: 'provider.groq',
hunyuan: 'provider.hunyuan',
hyperbolic: 'provider.hyperbolic',
infini: 'provider.infini',
jina: 'provider.jina',
lanyun: 'provider.lanyun',
lmstudio: 'provider.lmstudio',
minimax: 'provider.minimax',
mistral: 'provider.mistral',
modelscope: 'provider.modelscope',
moonshot: 'provider.moonshot',
'new-api': 'provider.new-api',
nvidia: 'provider.nvidia',
o3: 'provider.o3',
ocoolai: 'provider.ocoolai',
ovms: 'provider.ovms',
ollama: 'provider.ollama',
openai: 'provider.openai',
openrouter: 'provider.openrouter',
perplexity: 'provider.perplexity',
ph8: 'provider.ph8',
ppio: 'provider.ppio',
qiniu: 'provider.qiniu',
qwenlm: 'provider.qwenlm',
silicon: 'provider.silicon',
stepfun: 'provider.stepfun',
'tencent-cloud-ti': 'provider.tencent-cloud-ti',
together: 'provider.together',
tokenflux: 'provider.tokenflux',
vertexai: 'provider.vertexai',
voyageai: 'provider.voyageai',
xirang: 'provider.xirang',
yi: 'provider.yi',
zhinao: 'provider.zhinao',
zhipu: 'provider.zhipu',
poe: 'provider.poe',
aionly: 'provider.aionly',
longcat: 'provider.longcat',
huggingface: 'provider.huggingface',
sophnet: 'provider.sophnet',
gateway: 'provider.ai-gateway',
cerebras: 'provider.cerebras',
mimo: 'provider.mimo',
'volcano-coding': 'provider.volcano-coding',
'byteplus-coding': 'provider.byteplus-coding'
} as const
/**
* 获取内置供应商的本地化标签
* @param id - 供应商的id
* @returns 本地化后的供应商名称
* @remarks
* 该函数仅用于获取内置供应商的 i18n label
*
* 对于可能处理自定义供应商的情况,使用 getProviderName 或 getFancyProviderName 更安全
*/
export const getProviderLabel = (id: string): string => {
return getLabel(providerKeyMap, id)
}
const backupProgressKeyMap = {
completed: 'backup.progress.completed',
compressing: 'backup.progress.compressing',
copying_files: 'backup.progress.copying_files',
preparing_compression: 'backup.progress.preparing_compression',
preparing: 'backup.progress.preparing',
title: 'backup.progress.title',
writing_data: 'backup.progress.writing_data'
} as const
export const getBackupProgressLabel = (key: string): string => {
return getLabel(backupProgressKeyMap, key)
}
const restoreProgressKeyMap = {
completed: 'restore.progress.completed',
copying_files: 'restore.progress.copying_files',
extracted: 'restore.progress.extracted',
extracting: 'restore.progress.extracting',
preparing: 'restore.progress.preparing',
reading_data: 'restore.progress.reading_data',
title: 'restore.progress.title'
}
export const getRestoreProgressLabel = (key: string): string => {
return getLabel(restoreProgressKeyMap, key)
}
const titleKeyMap = {
// TODO: update i18n key
store: 'title.store',
apps: 'title.apps',
code: 'title.code',
files: 'title.files',
home: 'title.home',
knowledge: 'title.knowledge',
launchpad: 'title.launchpad',
'mcp-servers': 'title.mcp-servers',
memories: 'title.memories',
notes: 'title.notes',
paintings: 'title.paintings',
settings: 'title.settings',
translate: 'title.translate',
openclaw: 'openclaw.title'
} as const
export const getTitleLabel = (key: string): string => {
return getLabel(titleKeyMap, key)
}
const themeModeKeyMap = {
dark: 'settings.theme.dark',
light: 'settings.theme.light',
system: 'settings.theme.system'
} as const
export const getThemeModeLabel = (key: string): string => {
return getLabel(themeModeKeyMap, key)
}
// const sidebarIconKeyMap = {
// assistants: t('assistants.title'),
// store: t('assistants.presets.title'),
// paintings: t('paintings.title'),
// translate: t('translate.title'),
// minapp: t('minapp.title'),
// knowledge: t('knowledge.title'),
// files: t('files.title'),
// code_tools: t('code.title'),
// notes: t('notes.title')
// } as const
const sidebarIconKeyMap = {
assistants: 'assistants.title',
store: 'assistants.presets.title',
paintings: 'paintings.title',
translate: 'translate.title',
minapp: 'minapp.title',
knowledge: 'knowledge.title',
files: 'files.title',
code_tools: 'code.title',
notes: 'notes.title',
openclaw: 'openclaw.title'
} as const
export const getSidebarIconLabel = (key: string): string => {
return getLabel(sidebarIconKeyMap, key)
}
const shortcutKeyMap = {
action: 'settings.shortcuts.action',
actions: 'settings.shortcuts.actions',
clear_shortcut: 'settings.shortcuts.clear_shortcut',
clear_topic: 'settings.shortcuts.clear_topic',
rename_topic: 'settings.shortcuts.rename_topic',
copy_last_message: 'settings.shortcuts.copy_last_message',
edit_last_user_message: 'settings.shortcuts.edit_last_user_message',
enabled: 'settings.shortcuts.enabled',
exit_fullscreen: 'settings.shortcuts.exit_fullscreen',
label: 'settings.shortcuts.label',
mini_window: 'settings.shortcuts.mini_window',
new_topic: 'settings.shortcuts.new_topic',
press_shortcut: 'settings.shortcuts.press_shortcut',
reset_defaults: 'settings.shortcuts.reset_defaults',
reset_defaults_confirm: 'settings.shortcuts.reset_defaults_confirm',
reset_to_default: 'settings.shortcuts.reset_to_default',
search_message: 'settings.shortcuts.search_message',
search_message_in_chat: 'settings.shortcuts.search_message_in_chat',
select_model: 'settings.shortcuts.select_model',
selection_assistant_select_text: 'settings.shortcuts.selection_assistant_select_text',
selection_assistant_toggle: 'settings.shortcuts.selection_assistant_toggle',
show_app: 'settings.shortcuts.show_app',
show_settings: 'settings.shortcuts.show_settings',
title: 'settings.shortcuts.title',
toggle_new_context: 'settings.shortcuts.toggle_new_context',
toggle_show_assistants: 'settings.shortcuts.toggle_show_assistants',
toggle_show_topics: 'settings.shortcuts.toggle_show_topics',
zoom_in: 'settings.shortcuts.zoom_in',
zoom_out: 'settings.shortcuts.zoom_out',
zoom_reset: 'settings.shortcuts.zoom_reset'
} as const
export const getShortcutLabel = (key: string): string => {
return getLabel(shortcutKeyMap, key)
}
const selectionDescriptionKeyMap = {
mac: 'selection.settings.toolbar.trigger_mode.description_note.mac',
windows: 'selection.settings.toolbar.trigger_mode.description_note.windows'
} as const
export const getSelectionDescriptionLabel = (key: string): string => {
return getLabel(selectionDescriptionKeyMap, key)
}
const paintingsImageSizeOptionsKeyMap = {
auto: 'paintings.image_size_options.auto'
} as const
export const getPaintingsImageSizeOptionsLabel = (key: string): string => {
return paintingsImageSizeOptionsKeyMap[key] ? getLabel(paintingsImageSizeOptionsKeyMap, key) : key
}
const paintingsQualityOptionsKeyMap = {
auto: 'paintings.quality_options.auto',
high: 'paintings.quality_options.high',
low: 'paintings.quality_options.low',
medium: 'paintings.quality_options.medium'
} as const
export const getPaintingsQualityOptionsLabel = (key: string): string => {
return getLabel(paintingsQualityOptionsKeyMap, key)
}
const paintingsModerationOptionsKeyMap = {
auto: 'paintings.moderation_options.auto',
low: 'paintings.moderation_options.low'
} as const
export const getPaintingsModerationOptionsLabel = (key: string): string => {
return getLabel(paintingsModerationOptionsKeyMap, key)
}
const paintingsBackgroundOptionsKeyMap = {
auto: 'paintings.background_options.auto',
opaque: 'paintings.background_options.opaque',
transparent: 'paintings.background_options.transparent'
} as const
export const getPaintingsBackgroundOptionsLabel = (key: string): string => {
return getLabel(paintingsBackgroundOptionsKeyMap, key)
}
const mcpTypeKeyMap = {
inMemory: 'settings.mcp.types.inMemory',
sse: 'settings.mcp.types.sse',
stdio: 'settings.mcp.types.stdio',
streamableHttp: 'settings.mcp.types.streamableHttp'
} as const
export const getMcpTypeLabel = (key: string): string => {
return getLabel(mcpTypeKeyMap, key)
}
const mcpProviderDescriptionKeyMap = {
'302ai': 'settings.mcp.sync.providerDescriptions.302ai',
bailian: 'settings.mcp.sync.providerDescriptions.bailian',
lanyun: 'settings.mcp.sync.providerDescriptions.lanyun',
mcprouter: 'settings.mcp.sync.providerDescriptions.mcprouter',
modelscope: 'settings.mcp.sync.providerDescriptions.modelscope',
tokenflux: 'settings.mcp.sync.providerDescriptions.tokenflux'
} as const
export const getMcpProviderDescriptionLabel = (key: string): string => {
return getLabel(mcpProviderDescriptionKeyMap, key)
}
const miniappsStatusKeyMap = {
visible: 'settings.miniapps.visible',
disabled: 'settings.miniapps.disabled'
} as const
export const getMiniappsStatusLabel = (key: string): string => {
return getLabel(miniappsStatusKeyMap, key)
}
const httpMessageKeyMap = {
'400': 'error.http.400',
'401': 'error.http.401',
'403': 'error.http.403',
'404': 'error.http.404',
'429': 'error.http.429',
'500': 'error.http.500',
'502': 'error.http.502',
'503': 'error.http.503',
'504': 'error.http.504'
} as const
export const getHttpMessageLabel = (key: string): string => {
return getLabel(httpMessageKeyMap, key)
}
const fileFieldKeyMap = {
created_at: 'files.created_at',
size: 'files.size',
name: 'files.name'
} as const
export const getFileFieldLabel = (key: string): string => {
return getLabel(fileFieldKeyMap, key)
}
const builtInMcpDescriptionKeyMap: Record<BuiltinMCPServerName, string> = {
[BuiltinMCPServerNames.mcpAutoInstall]: 'settings.mcp.builtinServersDescriptions.mcp_auto_install',
[BuiltinMCPServerNames.memory]: 'settings.mcp.builtinServersDescriptions.memory',
[BuiltinMCPServerNames.sequentialThinking]: 'settings.mcp.builtinServersDescriptions.sequentialthinking',
[BuiltinMCPServerNames.braveSearch]: 'settings.mcp.builtinServersDescriptions.brave_search',
[BuiltinMCPServerNames.fetch]: 'settings.mcp.builtinServersDescriptions.fetch',
[BuiltinMCPServerNames.filesystem]: 'settings.mcp.builtinServersDescriptions.filesystem',
[BuiltinMCPServerNames.difyKnowledge]: 'settings.mcp.builtinServersDescriptions.dify_knowledge',
[BuiltinMCPServerNames.python]: 'settings.mcp.builtinServersDescriptions.python',
[BuiltinMCPServerNames.didiMCP]: 'settings.mcp.builtinServersDescriptions.didi_mcp',
[BuiltinMCPServerNames.browser]: 'settings.mcp.builtinServersDescriptions.browser',
[BuiltinMCPServerNames.nowledgeMem]: 'settings.mcp.builtinServersDescriptions.nowledge_mem',
[BuiltinMCPServerNames.hub]: 'settings.mcp.builtinServersDescriptions.hub'
} as const
export const getBuiltInMcpServerDescriptionLabel = (key: string): string => {
return getLabel(builtInMcpDescriptionKeyMap, key, t('settings.mcp.builtinServersDescriptions.no'))
}
const builtinOcrProviderKeyMap = {
system: 'ocr.builtin.system',
tesseract: '',
paddleocr: '',
ovocr: ''
} as const satisfies Record<BuiltinOcrProviderId, string>
export const getBuiltinOcrProviderLabel = (key: BuiltinOcrProviderId) => {
if (key === 'tesseract') return 'Tesseract'
else if (key == 'paddleocr') return 'PaddleOCR'
else if (key == 'ovocr') return 'Intel OV(NPU) OCR'
else return getLabel(builtinOcrProviderKeyMap, key)
}
export const getAgentTypeLabel = (key: AgentType) => {
switch (key) {
case 'claude-code':
return 'Claude Code'
default:
return 'Unknown Type'
}
}