Dictionary Translator (FeiMao-326)
Bulk tag swaps from a JSON or key=value table
- text
Tag translation is one of those jobs every non-English-speaking Stable Diffusion user hits eventually. Your prompt is full of Chinese terms, or your LoRA trainer's captions use one vocabulary while the checkpoint you're generating with expects another. You could hand-replace each one, or you could keep a mapping table and swap the whole batch in one shot. That's this node: a bulk dictionary replace driven by a JSON or key=value table.
How it works
Two inputs: text (the string to transform) and dictionary_data (the mapping). The node tries to parse dictionary_data as JSON first ({"key": "value", ...}), and if that fails, falls back to parsing line by line as key=value or key: value pairs. Whichever format parses, the result is a mapping dict, and every occurrence of a key in the text gets replaced with its value.
Two details make it smarter than a naive replace:
- Longest keys are replaced first. If your dictionary has both
CatandCatgirlas keys, replacingCatfirst would mangleCatgirlintogirlvalue. Sorting keys by length descending avoids that class of bug. - It accepts both JSON and flat text pairs, so you can maintain the table as a neat multi-line list (
Cinematic = cinematic lighting, 8k, highly detailed) or as a structured JSON blob depending on your mood.
The output is a single text string. If the dictionary fails to parse entirely (no JSON, no = or : lines), the node returns the input unchanged rather than erroring - graceful, but it means a typo in your table silently does nothing, so keep an eye on it.
Where it fits
The author's stated use case is the good one: mapping common terms to richer professional tags - turning Cinematic into cinematic lighting, 8k, highly detailed, or Chinese prompt vocabulary into proper booru tags the checkpoint actually understands. (As the KB notes, on booru-trained SDXL-lineage models, correct Danbooru tags beat loose natural-language phrasing every time, so a translation table like this genuinely improves results.)
It's also useful as a one-node cleanup gate before a template or sampler: throw a table of known-bad tokens at it and let it scrub the prompt in place. The main thing it doesn't do is regex - keys are literal strings only. For pattern-based extraction, the pack's Regex Extractor Pro covers that ground.
Inputs and outputs
text(STRING, multiline) - the text to translate.dictionary_data(STRING, multiline) - JSON object orkey=value/key: valuelines.text(STRING) - the result.
Installing
It ships in the FeiMao-326 pack (display name "Dictionary Translator (FeiMao-326)"), so it comes free with the other fifteen nodes. ComfyUI Manager (search "Comfyui-General-API-Node") or:
cd ComfyUI/custom_nodes
git clone https://github.com/FeiMao-326/Comfyui-General-API-Node.git
cd Comfyui-General-API-Node
pip install -r requirements.txt
Restart ComfyUI. Light dependencies (openai, numpy, Pillow, requests), no models to download.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| dictionary_data | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| text | STRING | — |