Nodes/ComfyUI_kkTranslator_nodes/PromptTranslateToText
ComfyUI Node

PromptTranslateToText

Translate your prompts offline, on your own machine — no API key, no cloud

By kingzcheung·Created 3 years ago·Updated about a year ago· 24
PromptTranslateToText
  • model
  • tokenizer
  • STRING
prompt_text你好

The node that ends the copy-paste-to-Google-Translate dance

Here's the situation this node exists for: SDXL-lineage models want English prompts. Booru tags, quality tags, the whole vocabulary - it's all English, and the models were trained on English captions. If English isn't your first language, every prompt becomes a trip to a translator tab and back. PromptTranslateToText puts that translation inside ComfyUI, running on your own machine with a local translation model. No API key, no account, no prompt text leaving your computer. That's the whole appeal, and it's a real one.

It's one half of the pack's offline path. LoadMarianMTCheckPoint loads a Helsinki-NLP OPUS-MT translation model into the graph; this node takes that model plus whatever text you typed and hands back the English translation as a STRING you can wire straight into a CLIP Text Encode's positive prompt. That's the entire workflow: load model → type your native-language prompt → feed the output forward. (This pack is a republished fork of the original kingzcheung/ComfyUI_kkTranslator_nodes, in case you've seen the older name.)

How it works

Under the hood it's textbook HuggingFace translation. Your prompt_text gets tokenized with return_tensors="pt", fed to model.generate(...), and the decoded tokens (special tokens skipped) are returned. It also prints the result to the ComfyUI console, which is a nice touch when you're debugging. The translation runs on CPU and the models are small - hundreds of MB, not gigabytes - so this is one of the rare nodes where you don't need to care about GPU memory at all. If you leave prompt_text empty, it returns an empty string instead of erroring, so you can leave the node in a graph without breaking your queue.

The inputs and output that matter

Three required inputs, two of which you'll rarely touch:

  • model and tokenizer - these come out of LoadMarianMTCheckPoint. Just wire them. The MODEL/TOKENIZER types are custom to this pack, so nothing else in ComfyUI produces them.
  • prompt_text - the one you actually edit. It's a multiline string box (defaults to 你好), so paste or type your whole prompt there.

Output is a single STRING - the English translation. It plugs into any text input, most usefully the text slot on CLIP Text Encode. Since it's just text, you can also chain it into prompt juggling or a workflow that batches several prompts at once.

Installing it

Two ways, both standard:

cd ComfyUI/custom_nodes
git clone https://github.com/AIGCTeam/ComfyUI_kkTranslator_nodes
python -m pip install -r requirements.txt

Then restart ComfyUI. Or, easier, use ComfyUI Manager - search for ComfyUI_kkTranslator_nodes and let it handle clone and deps. The requirements are torch, transformers, requests, plus a few stdlib modules, so there's no heavy CUDA build to worry about.

The gotchas

The README boasts that this node "doesn't require internet connection." That's true the way "offline maps" are true: the first run must download the model from HuggingFace, and only after that does the local cache make it offline. So your first queue run will stall on a download. And if you're in mainland China, HuggingFace is blocked - the pack's own Chinese README tells you to run with a mirror:

HF_ENDPOINT=https://hf-mirror.com python main.py

One more: transformers is pinned to 4.26.1, an old release from early 2023. In a big custom-node install that can collide with newer nodes that want a newer transformers - classic ComfyUI dependency hell. If unrelated nodes start misbehaving after install, that pin is the usual suspect. And if you need a language pair the pack doesn't ship (say Turkish or German), you'll have to add the checkpoint - more on that in the LoadMarianMTCheckPoint article. For the built-in pairs, though, this node just quietly works, and that's worth a lot.

CategorykkTranslator

Inputs (3)

NameTypeDefaultDescription
modelMODEL
tokenizerTOKENIZER
prompt_textSTRING你好

Outputs (1)

NameTypeDescription
STRINGSTRING