Skip to content

Commit 112a693

Browse files
huchenleigithub-actions
andauthored
[i18n] Translate setting options (#1858)
* Collect options * Translate setting options * Update locales [skip ci] * Normalize key * Revert change of logic --------- Co-authored-by: github-actions <github-actions@github.com>
1 parent 57701f6 commit 112a693

File tree

9 files changed

+418
-68
lines changed

9 files changed

+418
-68
lines changed

scripts/collect-i18n.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ test('collect-i18n', async ({ comfyPage }) => {
5252
id: setting.id,
5353
name: setting.name,
5454
tooltip: setting.tooltip,
55-
category: setting.category
55+
category: setting.category,
56+
options: setting.options
5657
}))
5758
})
5859

@@ -61,7 +62,19 @@ test('collect-i18n', async ({ comfyPage }) => {
6162
normalizeI18nKey(setting.id),
6263
{
6364
name: setting.name,
64-
tooltip: setting.tooltip
65+
tooltip: setting.tooltip,
66+
// Don't translate the locale options as each option is in its own language.
67+
// e.g. "English", "中文", "Русский", "日本語", "한국어"
68+
options:
69+
setting.options && setting.id !== 'Comfy.Locale'
70+
? Object.fromEntries(
71+
setting.options.map((option) => {
72+
const optionLabel =
73+
typeof option === 'string' ? option : option.text
74+
return [normalizeI18nKey(optionLabel), optionLabel]
75+
})
76+
)
77+
: undefined
6578
}
6679
])
6780
)

src/components/common/FormItem.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,11 @@ function getFormAttrs(item: FormItem) {
5555
case 'combo':
5656
attrs['options'] =
5757
typeof item.options === 'function'
58-
? item.options(formValue.value)
58+
? // @ts-expect-error: Audit and deprecate usage of legacy options type:
59+
// (value) => [string | {text: string, value: string}]
60+
item.options(formValue.value)
5961
: item.options
62+
6063
if (typeof item.options[0] !== 'string') {
6164
attrs['optionLabel'] = 'text'
6265
attrs['optionValue'] = 'value'

src/components/dialog/content/setting/SettingItem.vue

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,41 @@
2020
import Tag from 'primevue/tag'
2121
import FormItem from '@/components/common/FormItem.vue'
2222
import { useSettingStore } from '@/stores/settingStore'
23-
import { SettingParams } from '@/types/settingTypes'
23+
import type { SettingOption, SettingParams } from '@/types/settingTypes'
2424
import { computed } from 'vue'
2525
import { useI18n } from 'vue-i18n'
26+
import { normalizeI18nKey } from '@/utils/formatUtil'
2627
2728
const props = defineProps<{
2829
setting: SettingParams
2930
}>()
3031
3132
const { t } = useI18n()
33+
function translateOptions(options: (SettingOption | string)[]) {
34+
return options.map((option) => {
35+
const optionLabel = typeof option === 'string' ? option : option.text
36+
const optionValue = typeof option === 'string' ? option : option.value
37+
38+
return {
39+
text: t(
40+
`settingsDialog.${normalizeI18nKey(props.setting.id)}.options.${normalizeI18nKey(optionLabel)}`,
41+
optionLabel
42+
),
43+
value: optionValue
44+
}
45+
})
46+
}
47+
3248
const formItem = computed(() => {
33-
const normalizedId = props.setting.id.replace(/\./g, '_')
49+
const normalizedId = normalizeI18nKey(props.setting.id)
3450
return {
3551
...props.setting,
3652
name: t(`settingsDialog.${normalizedId}.name`, props.setting.name),
3753
tooltip: props.setting.tooltip
3854
? t(`settingsDialog.${normalizedId}.tooltip`, props.setting.tooltip)
55+
: undefined,
56+
options: props.setting.options
57+
? translateOptions(props.setting.options)
3958
: undefined
4059
}
4160
})

src/locales/en.json

Lines changed: 77 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,12 @@
220220
"name": "Enable fast-zoom shortcut (Ctrl + Shift + Drag)"
221221
},
222222
"Comfy_Graph_LinkMarkers": {
223-
"name": "Link midpoint markers"
223+
"name": "Link midpoint markers",
224+
"options": {
225+
"None": "None",
226+
"Circle": "Circle",
227+
"Arrow": "Arrow"
228+
}
224229
},
225230
"Comfy_Graph_ZoomSpeed": {
226231
"name": "Canvas zoom speed"
@@ -241,13 +246,29 @@
241246
"name": "Keybindings unset by the user"
242247
},
243248
"Comfy_LinkRelease_Action": {
244-
"name": "Action on link release (No modifier)"
249+
"name": "Action on link release (No modifier)",
250+
"options": {
251+
"context menu": "context menu",
252+
"search box": "search box",
253+
"no action": "no action"
254+
}
245255
},
246256
"Comfy_LinkRelease_ActionShift": {
247-
"name": "Action on link release (Shift)"
257+
"name": "Action on link release (Shift)",
258+
"options": {
259+
"context menu": "context menu",
260+
"search box": "search box",
261+
"no action": "no action"
262+
}
248263
},
249264
"Comfy_LinkRenderMode": {
250-
"name": "Link Render Mode"
265+
"name": "Link Render Mode",
266+
"options": {
267+
"Straight": "Straight",
268+
"Linear": "Linear",
269+
"Spline": "Spline",
270+
"Hidden": "Hidden"
271+
}
251272
},
252273
"Comfy_Locale": {
253274
"name": "Language"
@@ -273,7 +294,11 @@
273294
},
274295
"Comfy_ModelLibrary_NameFormat": {
275296
"name": "What name to display in the model library tree view",
276-
"tooltip": "Select \"filename\" to render a simplified view of the raw filename (without directory or \".safetensors\" extension) in the model list. Select \"title\" to display the configurable model metadata title."
297+
"tooltip": "Select \"filename\" to render a simplified view of the raw filename (without directory or \".safetensors\" extension) in the model list. Select \"title\" to display the configurable model metadata title.",
298+
"options": {
299+
"filename": "filename",
300+
"title": "title"
301+
}
277302
},
278303
"Comfy_Node_AutoSnapLinkToSlot": {
279304
"name": "Auto snap link to node slot",
@@ -305,13 +330,26 @@
305330
"tooltip": "When dragging a link over a node with viable input slot, highlight the node"
306331
},
307332
"Comfy_NodeBadge_NodeIdBadgeMode": {
308-
"name": "Node ID badge mode"
333+
"name": "Node ID badge mode",
334+
"options": {
335+
"None": "None",
336+
"Show all": "Show all"
337+
}
309338
},
310339
"Comfy_NodeBadge_NodeLifeCycleBadgeMode": {
311-
"name": "Node life cycle badge mode"
340+
"name": "Node life cycle badge mode",
341+
"options": {
342+
"None": "None",
343+
"Show all": "Show all"
344+
}
312345
},
313346
"Comfy_NodeBadge_NodeSourceBadgeMode": {
314-
"name": "Node source badge mode"
347+
"name": "Node source badge mode",
348+
"options": {
349+
"None": "None",
350+
"Show all": "Show all",
351+
"Hide built-in": "Hide built-in"
352+
}
315353
},
316354
"Comfy_NodeInputConversionSubmenus": {
317355
"name": "In the node context menu, place the entries that convert between input/widget in sub-menus."
@@ -326,7 +364,11 @@
326364
"name": "Node library bookmarks customization"
327365
},
328366
"Comfy_NodeSearchBoxImpl": {
329-
"name": "Node search box implementation"
367+
"name": "Node search box implementation",
368+
"options": {
369+
"default": "default",
370+
"litegraph (legacy)": "litegraph (legacy)"
371+
}
330372
},
331373
"Comfy_NodeSearchBoxImpl_NodePreview": {
332374
"name": "Node preview",
@@ -394,10 +436,18 @@
394436
"name": "Show extension panel in settings dialog"
395437
},
396438
"Comfy_Sidebar_Location": {
397-
"name": "Sidebar location"
439+
"name": "Sidebar location",
440+
"options": {
441+
"left": "left",
442+
"right": "right"
443+
}
398444
},
399445
"Comfy_Sidebar_Size": {
400-
"name": "Sidebar size"
446+
"name": "Sidebar size",
447+
"options": {
448+
"normal": "normal",
449+
"small": "small"
450+
}
401451
},
402452
"Comfy_SnapToGrid_GridSize": {
403453
"name": "Snap to grid size",
@@ -413,7 +463,12 @@
413463
"name": "Tree explorer item padding"
414464
},
415465
"Comfy_UseNewMenu": {
416-
"name": "Use new menu"
466+
"name": "Use new menu",
467+
"options": {
468+
"Disabled": "Disabled",
469+
"Top": "Top",
470+
"Bottom": "Bottom"
471+
}
417472
},
418473
"Comfy_Validation_NodeDefs": {
419474
"name": "Validate node definitions (slow)",
@@ -424,7 +479,11 @@
424479
},
425480
"Comfy_WidgetControlMode": {
426481
"name": "Widget control mode",
427-
"tooltip": "Controls when widget values are updated (randomize/increment/decrement), either before the prompt is queued or after."
482+
"tooltip": "Controls when widget values are updated (randomize/increment/decrement), either before the prompt is queued or after.",
483+
"options": {
484+
"before": "before",
485+
"after": "after"
486+
}
428487
},
429488
"Comfy_Window_UnloadConfirmation": {
430489
"name": "Show confirmation when closing window"
@@ -442,7 +501,11 @@
442501
"name": "Sort node IDs when saving workflow"
443502
},
444503
"Comfy_Workflow_WorkflowTabsPosition": {
445-
"name": "Opened workflows position"
504+
"name": "Opened workflows position",
505+
"options": {
506+
"Sidebar": "Sidebar",
507+
"Topbar": "Topbar"
508+
}
446509
},
447510
"LiteGraph_Canvas_MaximumFps": {
448511
"name": "Maxium FPS",

0 commit comments

Comments
 (0)