Translate node title and description (#1822)

* Collect node def i18n

* Add collected en locale

* Sort by node id

* Add translations

* Show translated node def

* Update locales [skip ci]

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Chenlei Hu
2024-12-06 13:56:54 -08:00
committed by GitHub
parent ae26390776
commit 517ae56763
8 changed files with 3265 additions and 22 deletions

View File

@@ -5,6 +5,7 @@ import { SERVER_CONFIG_ITEMS } from '../src/constants/serverConfig'
import { formatCamelCase, normalizeI18nKey } from '../src/utils/formatUtil'
import type { ComfyCommandImpl } from '../src/stores/commandStore'
import type { FormItem, SettingParams } from '../src/types/settingTypes'
import type { ComfyApi } from '../src/scripts/api'
const localePath = './src/locales/en.json'
const extractMenuCommandLocaleStrings = (): Set<string> => {
@@ -27,6 +28,8 @@ test('collect-i18n', async ({ comfyPage }) => {
})
const locale = JSON.parse(fs.readFileSync(localePath, 'utf-8'))
// Commands
const menuLabels = extractMenuCommandLocaleStrings()
const commandMenuLabels = new Set(
commands.map((command) => command.menubarLabel ?? command.label ?? '')
@@ -38,6 +41,7 @@ test('collect-i18n', async ({ comfyPage }) => {
Array.from(allLabels).map((label) => [normalizeI18nKey(label), label])
)
// Settings
const settings = await comfyPage.page.evaluate(() => {
const workspace = window['app'].extensionManager
const settings = workspace.setting.settings as Record<string, SettingParams>
@@ -72,6 +76,7 @@ test('collect-i18n', async ({ comfyPage }) => {
])
)
// Server Configs
const allServerConfigsLocale = Object.fromEntries(
SERVER_CONFIG_ITEMS.map((config) => [
normalizeI18nKey(config.id),
@@ -91,6 +96,24 @@ test('collect-i18n', async ({ comfyPage }) => {
])
)
// Node Definitions
const nodeDefs = await comfyPage.page.evaluate(async () => {
const api = window['app'].api as ComfyApi
return await api.getNodeDefs()
})
const allNodeDefsLocale = Object.fromEntries(
Object.values(nodeDefs)
.sort((a, b) => a.name.localeCompare(b.name))
.map((nodeDef) => [
normalizeI18nKey(nodeDef.name),
{
display_name: nodeDef.display_name ?? nodeDef.name,
description: nodeDef.description || undefined
}
])
)
fs.writeFileSync(
localePath,
JSON.stringify(
@@ -105,7 +128,8 @@ test('collect-i18n', async ({ comfyPage }) => {
...allSettingCategoriesLocale
},
serverConfigItems: allServerConfigsLocale,
serverConfigCategories: allServerConfigCategoriesLocale
serverConfigCategories: allServerConfigCategoriesLocale,
nodeDefs: allNodeDefsLocale
},
null,
2