import * as fs from 'fs' import { comfyPageFixture as test } from '../browser_tests/fixtures/ComfyPage' import { CORE_MENU_COMMANDS } from '../src/constants/coreMenuCommands' import { normalizeI18nKey } from '../src/utils/formatUtil' import type { ComfyCommandImpl } from '../src/stores/commandStore' import type { SettingParams } from '../src/types/settingTypes' const localePath = './src/locales/en.json' const extractMenuCommandLocaleStrings = (): Set => { const labels = new Set() 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]) ) const settings = await comfyPage.page.evaluate(() => { const workspace = window['app'].extensionManager const settings = workspace.setting.settings as Record return Object.values(settings) .sort((a, b) => a.id.localeCompare(b.id)) .map((setting) => ({ id: setting.id, name: setting.name, tooltip: setting.tooltip })) }) const allSettingsLocale = Object.fromEntries( settings.map((setting) => [ normalizeI18nKey(setting.id), { name: setting.name, tooltip: setting.tooltip } ]) ) fs.writeFileSync( localePath, JSON.stringify( { ...locale, menuLabels: allLabelsLocale, settingsDialog: allSettingsLocale }, null, 2 ) ) })