PJ Text Translator (Bi-Directional)
Translate Chinese prompts to English offline, on your own GPU, no API key
- text
- original_text
The name tells you the pitch: bi-directional translation, and it's the star of the pongjoo/ComfyUI-PJLatent pack. Drop a Chinese prompt in, get a clean English prompt out - or the reverse - with no API key, no cloud call, nothing leaving your machine. It runs the Helsinki-NLP opus-mt translation models locally through Hugging Face's transformers library, on your GPU if you've got one.
Who is this for? Anyone writing SD or Flux prompts in Chinese, and anyone who routinely gets workflows or prompts shared in Chinese and wants them in the form the English-trained models understand best. The author's framing is exactly that: it's a prompt-translation helper, not a general-purpose translator. opus-mt is a classic statistical neural MT model - it's fast, small, and decent, but it's not an LLM. Expect literal, grammatical translation, not creative prompt-engineering. If you want "add cinematic rim lighting and bokeh" rather than "add the light on the edge of the person", an LLM does that better. For a faithful zh→en conversion inline in your graph, this is the one.
How it works
It detects the direction itself. In Auto mode it scans the input for Chinese characters: found any → zh→en, otherwise → en→zh. So yes, genuinely bi-directional - feed it English and it returns Chinese. That's the feature and the trap, discussed below. You can also pin the direction with ZH -> EN or EN -> ZH.
The model side is where the cleverness is. On first use it looks for opus-mt-zh-en / opus-mt-en-zh in a handful of standard model folders; if missing, it auto-downloads the required files from HuggingFace - with a fallback to the hf-mirror.com mirror if HuggingFace itself is unreachable, which is a thoughtful touch if you're behind the Great Firewall. Models land in ComfyUI/models/prompt_generator/. After that it's fully offline. The model dropdown also auto-detects any opus/zh/translation-named model folders it finds on disk, so if you already have one from another node pack it'll offer it.
Inputs and outputs
text- the prompt, multiline.mode- Auto / ZH→EN / EN→ZH. Set it explicitly once you know which way you're going.clean_punctuation- default on. Converts full-width Chinese punctuation (,。!?) to half-width with proper spacing, so your translated prompt doesn't carry,that ComfyUI's CLIP parser chokes on. Applied on the zh→en direction.keep_in_memory- default on. Caches the loaded model so repeat translations are milliseconds instead of reloading the weights each time. Turn it off if you're memory-tight and translating rarely.prefix/suffix- optional strings glued around the result (quality tags like "masterpiece, best quality" go naturally inprefix). On zh→en they're joined with ", ".device- auto / cuda / cpu.
Outputs: text (the translation) and original_text (a passthrough of what you put in - handy if you want to keep the source visible downstream or debug a translation).
Installing it
ComfyUI Manager, search PJLatent, or:
cd ComfyUI/custom_nodes/
git clone https://github.com/pongjoo/ComfyUI-PJLatent.git
Restart. The node is under Add Node → PJ_Nodes → Text.
Here's the one real install gotcha, and it's a genuine "read the source" find: the pack ships no requirements.txt, and the node imports transformers and huggingface_hub lazily, inside the translate call. huggingface_hub usually rides along with ComfyUI itself, but transformers almost certainly is not installed. Your first run will throw ModuleNotFoundError: No module named 'transformers'. Fix:
pip install transformers
Then the first real run downloads a few hundred MB of model files into models/prompt_generator/, so budget that first hit. If auto-download fails, the README's manual path is to drop the model folders in the same location yourself.
The trap
Auto mode is bi-directional, and people forget that on day two. If you're building a workflow that translates your Chinese prompt to English, leave it in Auto and it works - until you test it by pasting an English prompt and get Chinese back. For a prompt-translation workflow you'll actually run, pin ZH -> EN so the direction never surprises you.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| mode | COMBO | Auto (智能双向检测) | 3 options: Auto (智能双向检测), ZH -> EN (中译英), EN -> ZH (英译中) |
| model | COMBO | 1 options: Auto / opus-mt-zh-en (自动检测/自动下载) | |
| device | COMBO | auto | 3 options: auto, cuda, cpu |
| clean_punctuation | BOOLEAN | true | — |
| keep_in_memory | BOOLEAN | true | — |
| prefixopt | STRING | — | |
| suffixopt | STRING | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| text | STRING | — |
| original_text | STRING | — |