mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-04 04:30:04 +00:00
Translate topbar command menu (#1784)
* Rename script * Translate menu labels * Update translations * Display translated menu items
This commit is contained in:
57
scripts/update-constants-locale.ts
Normal file
57
scripts/update-constants-locale.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import fs from 'fs'
|
||||
import { CORE_SETTINGS } from '../src/constants/coreSettings'
|
||||
import { CORE_MENU_COMMANDS } from '../src/constants/coreMenuCommands'
|
||||
|
||||
interface SettingLocale {
|
||||
name: string
|
||||
tooltip?: string
|
||||
}
|
||||
|
||||
const extractSettingLocaleStrings = (): Record<string, SettingLocale> => {
|
||||
return Object.fromEntries(
|
||||
CORE_SETTINGS.sort((a, b) => a.id.localeCompare(b.id)).map((setting) => [
|
||||
// '.' is not allowed in JSON keys, so we replace it with '_'
|
||||
setting.id.replace(/\./g, '_'),
|
||||
{
|
||||
name: setting.name,
|
||||
tooltip: setting.tooltip
|
||||
}
|
||||
])
|
||||
)
|
||||
}
|
||||
|
||||
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'))
|
||||
fs.writeFileSync(
|
||||
localePath,
|
||||
JSON.stringify(
|
||||
{
|
||||
...globalLocale,
|
||||
settingsDialog: {
|
||||
...(globalLocale.settingsDialog ?? {}),
|
||||
...settingLocaleStrings
|
||||
},
|
||||
menuLabels: {
|
||||
...(globalLocale.menuLabels ?? {}),
|
||||
...menuCommandLocaleStrings
|
||||
}
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
main()
|
||||
@@ -1,39 +0,0 @@
|
||||
import fs from 'fs'
|
||||
import { CORE_SETTINGS } from '../src/constants/coreSettings'
|
||||
|
||||
interface SettingLocale {
|
||||
name: string
|
||||
tooltip?: string
|
||||
}
|
||||
|
||||
const extractLocaleStrings = (): Record<string, SettingLocale> => {
|
||||
return Object.fromEntries(
|
||||
CORE_SETTINGS.sort((a, b) => a.id.localeCompare(b.id)).map((setting) => [
|
||||
// '.' is not allowed in JSON keys, so we replace it with '_'
|
||||
setting.id.replace(/\./g, '_'),
|
||||
{
|
||||
name: setting.name,
|
||||
tooltip: setting.tooltip
|
||||
}
|
||||
])
|
||||
)
|
||||
}
|
||||
|
||||
const main = () => {
|
||||
const localeStrings = extractLocaleStrings()
|
||||
const localePath = './src/locales/en.json'
|
||||
const globalLocale = JSON.parse(fs.readFileSync(localePath, 'utf-8'))
|
||||
fs.writeFileSync(
|
||||
localePath,
|
||||
JSON.stringify(
|
||||
{
|
||||
...globalLocale,
|
||||
settingsDialog: { ...globalLocale.settingsDialog, ...localeStrings }
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user