mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-28 18:54:09 +00:00
Translate command label on top command dropdown menu (#1792)
* collect i18n with playwright * Add command label translation * Normalize i18n object key
This commit is contained in:
50
scripts/collect-i18n.ts
Normal file
50
scripts/collect-i18n.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import * as fs from 'fs'
|
||||
import { comfyPageFixture as test } from '../browser_tests/fixtures/ComfyPage'
|
||||
import type { ComfyCommandImpl } from '../src/stores/commandStore'
|
||||
import { CORE_MENU_COMMANDS } from '../src/constants/coreMenuCommands'
|
||||
import { normalizeI18nKey } from '../src/utils/formatUtil'
|
||||
|
||||
const localePath = './src/locales/en.json'
|
||||
const extractMenuCommandLocaleStrings = (): Set<string> => {
|
||||
const labels = new Set<string>()
|
||||
for (const [category, _] of CORE_MENU_COMMANDS) {
|
||||
category.forEach((category) => labels.add(category))
|
||||
}
|
||||
return labels
|
||||
}
|
||||
|
||||
test('collect-i18n', async ({ comfyPage }) => {
|
||||
const commands = await comfyPage.page.evaluate(() => {
|
||||
const workspace = window['app'].extensionManager
|
||||
const commands = workspace.command.commands as ComfyCommandImpl[]
|
||||
return commands.map((command) => ({
|
||||
id: command.id,
|
||||
label: command.label,
|
||||
menubarLabel: command.menubarLabel
|
||||
}))
|
||||
})
|
||||
|
||||
const locale = JSON.parse(fs.readFileSync(localePath, 'utf-8'))
|
||||
const menuLabels = extractMenuCommandLocaleStrings()
|
||||
const commandMenuLabels = new Set(
|
||||
commands.map((command) => command.menubarLabel ?? command.label ?? '')
|
||||
)
|
||||
const allLabels = new Set([...menuLabels, ...commandMenuLabels])
|
||||
allLabels.delete('')
|
||||
|
||||
const allLabelsLocale = Object.fromEntries(
|
||||
Array.from(allLabels).map((label) => [normalizeI18nKey(label), label])
|
||||
)
|
||||
|
||||
fs.writeFileSync(
|
||||
localePath,
|
||||
JSON.stringify(
|
||||
{
|
||||
...locale,
|
||||
menuLabels: allLabelsLocale
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
)
|
||||
})
|
||||
@@ -1,6 +1,5 @@
|
||||
import fs from 'fs'
|
||||
import { CORE_SETTINGS } from '../src/constants/coreSettings'
|
||||
import { CORE_MENU_COMMANDS } from '../src/constants/coreMenuCommands'
|
||||
|
||||
interface SettingLocale {
|
||||
name: string
|
||||
@@ -20,17 +19,8 @@ const extractSettingLocaleStrings = (): Record<string, SettingLocale> => {
|
||||
)
|
||||
}
|
||||
|
||||
const extractMenuCommandLocaleStrings = (): Record<string, string> => {
|
||||
const labels = new Set<string>()
|
||||
for (const [category, _] of CORE_MENU_COMMANDS) {
|
||||
category.forEach((category) => labels.add(category))
|
||||
}
|
||||
return Object.fromEntries(Array.from(labels).map((label) => [label, label]))
|
||||
}
|
||||
|
||||
const main = () => {
|
||||
const settingLocaleStrings = extractSettingLocaleStrings()
|
||||
const menuCommandLocaleStrings = extractMenuCommandLocaleStrings()
|
||||
|
||||
const localePath = './src/locales/en.json'
|
||||
const globalLocale = JSON.parse(fs.readFileSync(localePath, 'utf-8'))
|
||||
@@ -42,10 +32,6 @@ const main = () => {
|
||||
settingsDialog: {
|
||||
...(globalLocale.settingsDialog ?? {}),
|
||||
...settingLocaleStrings
|
||||
},
|
||||
menuLabels: {
|
||||
...(globalLocale.menuLabels ?? {}),
|
||||
...menuCommandLocaleStrings
|
||||
}
|
||||
},
|
||||
null,
|
||||
|
||||
Reference in New Issue
Block a user