mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-19 22:09:37 +00:00
29 lines
779 B
TypeScript
29 lines
779 B
TypeScript
import { normalizeI18nKey } from '@/utils/formatUtil'
|
|
|
|
type NodeTitleInfo = {
|
|
title?: string | number | null
|
|
type?: string | number | null
|
|
}
|
|
|
|
type StaticTranslate = (key: string, fallbackMessage: string) => string
|
|
|
|
type ResolveNodeDisplayNameOptions = {
|
|
emptyLabel: string
|
|
untitledLabel: string
|
|
st: StaticTranslate
|
|
}
|
|
|
|
export function resolveNodeDisplayName(
|
|
node: NodeTitleInfo | null | undefined,
|
|
options: ResolveNodeDisplayNameOptions
|
|
): string {
|
|
if (!node) return options.emptyLabel
|
|
|
|
const title = (node.title ?? '').toString().trim()
|
|
if (title.length > 0) return title
|
|
|
|
const nodeType = (node.type ?? '').toString().trim() || options.untitledLabel
|
|
const key = `nodeDefs.${normalizeI18nKey(nodeType)}.display_name`
|
|
return options.st(key, nodeType)
|
|
}
|