Files
ComfyUI_frontend/scripts/update-constants-locale.ts
Chenlei Hu 7986aebf27 Translate command label on top command dropdown menu (#1792)
* collect i18n with playwright

* Add command label translation

* Normalize i18n object key
2024-12-04 13:19:53 -05:00

44 lines
983 B
TypeScript

import fs from 'fs'
import { CORE_SETTINGS } from '../src/constants/coreSettings'
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 main = () => {
const settingLocaleStrings = extractSettingLocaleStrings()
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
}
},
null,
2
)
)
}
main()