Generative · Translate Prompt
A Translation Prompt That Knows How Much Room The Text Has
- blocks
- prompt
"Translate this ad into German" is the easy half. The hard half is that German runs about 25% longer than English, the panel the text sits in didn't get any bigger, and an LLM with no idea about any of that will cheerfully hand you a sentence that doesn't fit. Generative · Translate Prompt is the node that builds a translation request with character budgets attached to every line, so the model knows what it's being asked to squeeze into.
One input of blocks, one input of target language, one long prompt string out.
The mechanism: budgets, not vibes
Feed it the blocks from Generative · Parse Blocks JSON and it does the arithmetic before it writes a word.
For each translatable block it looks at the source text's own width, then at the panel behind it - containerBbox, if the analysis pass provided one. It's allowed to borrow 45% of the panel's slack over the text box's width, capped at 96% of the panel's own width. No panel means a flat 5% overhang and no more. The ratio between what you have and what you need is what the block can grow by.
That ratio then becomes a per-line character limit, adjusted by a per-language width factor baked into the pack: German 1.08, Dutch 1.06, French 1.05, Spanish and Italian 1.02. And the row the model actually reads looks roughly like this:
3. [title] "Powerful 62cc Engine"(每行不超过 24 字符)
Two special cases change the shape of that row. Blocks marked with a low growth allowance (under 25%) are the tight, label-like ones, and they're the only ones that get a char limit at all. Text over 120 characters is treated as a paragraph instead: it gets a total cap and a line count, because a disclaimer has fixed space for N lines and the shape matters more than any individual line.
What the rules template adds
The prompt body is a long, opinionated rule list, and it's the best thing in this node. The ones that actually change output quality:
- Line structure is preserved. The source's newlines are marked, and the translation has to break in the same places. No merging two lines into one, no swapping words across a break.
- Units and model numbers are untouchable. HP stays HP (explicitly not PS), RPM stays RPM, cc stays cc. No localisation, no conversion, no space inserted into
1500W. - Lines that are only digits and units stay that way. A spec line
62cc 3.8HP 12000RPMcan reorder but can't grow description words. - Long paragraphs must stay long. The rule is a floor, not a ceiling - a legal disclaimer's translation should be at least 85% of the source length, because the space was reserved for the source's word count and a tidy short version leaves a visible hole.
- Output is one JSON object, keyed by block ID. No markdown fence, no commentary. That's exactly what
Generative · Apply Translationsparses next.
There's also a per-language patch section - German compound-noun formation and hyphenation, French agreement and apostrophe rules, Spanish accents - and role hints (title, bullet, label, paragraph) so a bullet can be phrased differently from a headline.
Inputs and outputs
-
blocks- JSON. The normalised block list. -
target_lang- STRING, and note the default is the word德语(German, in Chinese). It's free text, so writeGerman,Deutschor德语- whatever your model understands best. It goes into the prompt as prose, not as a code. -
prompt- STRING. Wire it into your LLM's text input. The output of that LLM goes intoGenerative · Apply Translations.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/rexqin/comfyui-vevor-mask-union
# restart ComfyUI
Manager → Vevor Mask Union. Zero dependencies; the prompt text ships as data files inside the pack. Node search: "Translate Prompt".
Where people get burned
The budgets are only as good as the analysis. Every char limit comes from bbox and containerBbox. Wrong boxes, or bbox given as corners instead of [x, y, w, h], and the limits are fiction - usually too generous, which is how you get a translation that doesn't fit its panel. If the char limits in the prompt look absurd (3 characters for a headline, or 200), stop and check the blocks.
Don't ask for two languages at once. The width factors and the language patch section are keyed to a single target. "German and French" gets you German-sized budgets for French text.
The model can still ignore the limits. This node writes the brief; it can't enforce it. That's what the pack's space-budget and review/retry path exists for - a second pass that names the blocks that overflowed and tells the model to tighten them without dropping information. If you're getting long translations that break layout, add the review step rather than making the limits harsher; harsher limits just get you truncated meaning.
Everything is in Chinese. The rule template is Chinese prose, which most current multilingual models handle fine and small English-tuned local models handle poorly. If you're running a 3B behind this, test it on one image before you queue fifty.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| blocks | JSON | — | |
| target_lang | STRING | 德语 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| prompt | STRING | — |