Nodes/ComfyUI-Translate/Translate (Gemma 4B)
ComfyUI Node

Translate (Gemma 4B)

Translate text (and text inside images) locally with TranslateGemma 4B — no API key, no cloud

By wanaigc·Created 8 months ago·Updated 8 months ago· 2
Translate (Gemma 4B)
  • image
  • translated_text
model_name
source_lang_selecten (英文 - English)
source_manual_override
target_lang_selectzh (中文 - Chinese)
target_manual_override
text_input

The name is not hype: this node runs Google's TranslateGemma-4b-it translation model on your own GPU, no API key, no account, no network call. If you've ever built a workflow that ends with you copying a prompt into Google Translate and pasting the result back, this is the node that kills that step - and it also reads text inside images and translates it, which the copy-paste workflow can't do at all.

Why would you want a translator sitting in your graph? Because a lot of the best open checkpoints and LoRAs out of the Asian community are tuned on Chinese or Japanese prompt vocabulary, and writing a good prompt in a language you don't speak is a coin flip. TranslateGemma is a much better prompt-travel companion than a generic chat LLM, because translation is its whole job - Google trained the family specifically for that, at 250+ languages, and the 4B it variant is the instruction-tuned, image-capable top end of the line. In the LLM-in-the-graph picture the KB paints, this is the "small and obedient, not large and clever" end of the spectrum: a purpose-built tool that follows a format and stops, which is exactly the right profile for a workflow helper.

How it works

The node is thin on purpose. It loads the model from ComfyUI/models/Translate/<folder> using HuggingFace's AutoModelForImageTextToText + AutoProcessor, builds a chat message with your source/target language codes, runs it through the model's chat template, and decodes the result with greedy sampling (do_sample=False, max 512 tokens). It picks bfloat16 when your card supports it, falls back to float16, and uses device_map="auto" so it can spill to CPU RAM if VRAM runs tight.

Two details matter day to day. First, the model is cached globally: load once, and every subsequent run reuses it - no repeated 8GB loads mid-workflow. Second, the whole thing is a ~250-line Python file that does exactly one job, which, given that a past "LLM vision" ComfyUI node turned out to be malware, is a genuinely reassuring thing to be able to say.

The inputs that matter

  • model_name - a dropdown of the folders sitting in models/Translate. This is your only choice if you ever keep two model versions around.
  • source_lang_select / target_lang_select - 25 options in the dropdown, from en and zh up through Thai, Ukrainian, and regional variants like zh-CN, zh-TW, en-US. Source defaults to English, target to Chinese.
  • source_manual_override / target_manual_override - a raw language code (like sw for Swahili) that overrides the dropdown. This is how you reach the other ~240 languages TranslateGemma knows.
  • text_input - multiline text to translate. Ignored when an image is attached.
  • image (optional) - any IMAGE. It translates the text visible in the picture. Fair warning: it takes only the first frame, so feeding a video batch gives you frame 0.

Output: a single translated_text STRING. Wire it into a Show Text node, a text-file saver, or straight into a CLIP text encode.

Installing it

ComfyUI Manager handles it - search "ComfyUI-Translate" - or clone it directly:

cd ComfyUI/custom_nodes
git clone https://github.com/wanaigc/ComfyUI-Translate
cd ComfyUI-Translate
pip install -r requirements.txt

That pulls in transformers>=4.48.0, accelerate, protobuf, and sentencepiece. Use the same Python environment ComfyUI runs on, and restart after installing.

The gotcha: the model does not download itself

Most modern nodes fetch weights for you. This one does not - the README is explicit that you grab google/translategemma-4b-it yourself from HuggingFace (or ModelScope, if you're in China, where it's the fast path) and drop it here:

ComfyUI/models/Translate/translategemma-4b-it/
  ├── config.json
  ├── model.safetensors
  ├── tokenizer.json
  └── ...

You'll know you've skipped this step: the model_name dropdown shows a Chinese placeholder meaning roughly "please put the model in the models/Translate directory," and running throws an error. It's a 4B model, so budget about 8GB VRAM (or CPU offload at the cost of speed). Once the folder is there, refresh the node or restart ComfyUI and it'll appear in the dropdown.

Where people trip

  • Placeholder in model_name → nothing in models/Translate. That's the model download, not a bug.
  • Load failure → the error text tells you to check transformers>=4.48.0 and accelerate. Reinstall them into ComfyUI's Python, not a random venv.
  • Nothing translated → empty text and no image is a hard error by design; feed one or the other.
  • VRAM pressure → 4B bf16 plus the diffusion model on one card is real. If it OOMs, close the gap by running the translator and the sampler in separate stages, or accept slow CPU offload.

For a private, offline, free translation step in your prompt pipeline, this is the one I'd reach for - just don't skip the manual model download.

CategoryTranslate/Local

Inputs (7)

NameTypeDefaultDescription
model_nameCOMBO1 options: 请将模型放入 models/Translate 目录
source_lang_selectCOMBOen (英文 - English)25 options: en (英文 - English), zh (中文 - Chinese), ja (日文 - Japanese), ko (韩文 - Korean), fr (法文 - French), de (德文 - German), +19
source_manual_overrideSTRING
target_lang_selectCOMBOzh (中文 - Chinese)25 options: en (英文 - English), zh (中文 - Chinese), ja (日文 - Japanese), ko (韩文 - Korean), fr (法文 - French), de (德文 - German), +19
target_manual_overrideSTRING
text_inputSTRING
imageoptIMAGE

Outputs (1)

NameTypeDescription
translated_textSTRING