Nodes/Vevor Mask Union/Generative · Apply Translations
ComfyUI Node

Generative · Apply Translations

Merging The Model's Answer Back Into Your Blocks Without Losing Any

By rexqin·Created about a month ago·Updated 19 days ago· 0
Generative · Apply Translations
  • blocks
  • blocks
◄translation_response—►

Two inputs, one output, no widgets: this is the join in the middle of the translation pipeline. Blocks go in with an empty translation field on every one of them; the language model's reply goes in as raw text; blocks come out with the translations filled in. If you were going to write this as a Script node, you'd write it once and then spend an evening debugging why block 7 came back in the wrong language because your string indexing was off by one. This node does it once, properly.

How the merge works

The reply is expected to be a flat JSON object mapping block ID to translated string - exactly the format Generative · Translate Prompt asks for. The node strips a markdown fence if there is one, slices from the first { to the last }, parses it, and then for every key that converts to an integer it walks the blocks and assigns translation on the block with that id.

Two details in there are worth knowing:

Only integer keys count. Anything the model wrapped in a nested object, or keyed by text ("Powerful 62cc Engine": "..."), is skipped without complaint. That's why a chatty model that decides to return {"translations": {...}} silently produces a completely untranslated block list - no exception, no warning, just everything downstream working from empty strings.

Escaped newlines get unescaped. The prompt asks for line breaks as a literal \n inside the JSON string. This node converts \\n back into a real newline and trims the result, so the block's translation is immediately usable as multi-line text by the generate-prompt builder and the renderer. If you hand-escape newlines yourself you'll end up with double-escaped junk.

Blocks the model didn't answer keep translation = None. The node never invents text, never truncates, and never touches the source text - a partial answer stays partial, which is the correct behaviour and means partial answers stay your problem.

Inputs and outputs

  • blocks - JSON. From Generative · Parse Blocks JSON, or from any earlier stage that added information to the blocks.

  • translation_response - STRING, connect-only. The raw reply from the language model. No parsing of it happens before this point, so don't pre-process it.

  • blocks - JSON, with translation populated per block. That goes to the generate-prompt builder (for a redraw by an image model) or to a text renderer (for drawing with a real font file). Same block IDs, same geometry - just now bilingual.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/rexqin/comfyui-vevor-mask-union
# restart ComfyUI

Manager → Vevor Mask Union. No dependencies, nothing to download, no key. Node search: "Apply Translations".

Where people get burned

A blocked or refused reply is indistinguishable from an empty one. Both produce zero populated blocks. If your final image comes back with text that's still in the source language, this node did its job: it faithfully applied "nothing". Look at the raw translation response, not at the blocks.

Brace counting is naive, and that's usually fine. First { to last } handles a fence, a preamble and a trailing "let me know if…" in one go. It does not handle a reply with two separate JSON objects, or a translation that itself contains an unbalanced brace - rare, but a German sentence with a stray } inside a string will break the parse. Look at the raw response when blocks come back empty.

Don't reorder blocks between parse and apply. The IDs assigned by the parser are positional, and this node matches on them. Get the two stages out of sync - re-run the parser, filter a block out, dedupe - and translations land on the wrong regions. The failure is subtle in the worst way: mostly plausible output with two labels swapped.

This is the merge point, so it's also the right place to inspect. A Preview on a JSON socket is worth more than any amount of guessing: the blocks coming out of here tell you, in one glance, which regions got translated, which came back None, and whether the newlines landed where the source had them. Five seconds here saves twenty minutes of blaming the image model.

Categoryvevor/generative

Inputs (2)

NameTypeDefaultDescription
blocksJSON—
translation_responseSTRING—

Outputs (1)

NameTypeDescription
blocksJSON—