Nodes/ComfyUI-TranslationNode/🈯 Translation Node (Offline)
ComfyUI Node

🈯 Translation Node (Offline)

Write prompts in your own language β€” this node translates them on your machine

By petr-prΒ·Created 10 months agoΒ·Updated 10 months agoΒ· 2
🈯 Translation Node (Offline)
    • translated_text
    β—„textEnter text to translate...β–Ί
    β—„target_langenβ–Ί
    β—„source_langautoβ–Ί

    The name isn't a sales pitch: 🈯 Translation Node (Offline) is genuinely offline. No API key, no cloud round-trip, no "your prompt is now a training sample somewhere." It loads Facebook's M2M-100 translation model onto your machine, and everything stays local. If the whole point of local generation is that your prompts, images, and workflows don't leave your box, this is the translation node that matches the vibe.

    Why you'd reach for it: image models are trained on English captions, and most text encoders behave best when the prompt is in English. The KB's prompt-engineering essay makes that case hard - the community's standard move is to have an LLM translate your intent into a well-structured English prompt. This node does the simpler, cheaper version: you type the prompt in Czech, Spanish, German, whatever, and it comes out the other end in English, ready to wire into your text encoder. It's also handy for non-prompt jobs - subtitles, titles, captions that your workflow generates and needs in another language.

    How it works

    Under the hood it's the M2M-100 418M model (a multilingual encoder-decoder transformer) running through Hugging Face Transformers. The flow is about as standard as translation gets: tokenize the input, set the source language, generate with a forced target-language token, decode. Three implementation details are worth knowing because they shape how you use it:

    • Source detection is langdetect, not the model. With source_lang set to auto it runs a lightweight language detector (detect()), and if that throws, it quietly falls back to English. Image prompts are short and taggy - exactly the input a statistical detector can fumble. If you're translating more than a couple of words, set the source explicitly.
    • The model is cached after the first load. A module-level cache keeps the tokenizer + model in memory, so the first run pays the price and everything after is fast.
    • Empty text doesn't error - it returns the literal string ⚠️ Empty input text. Downstream that can silently poison a prompt. Worth filtering blank input upstream.

    The inputs that matter

    There are only three, all required:

    • text (multiline STRING) - what you want translated.
    • target_lang (STRING, default en) - the M2M-100 two-letter code of the output language. en, de, es, cs, zh… the codebase resolves it via get_lang_id, so it has to be a code M2M-100 actually knows, not a full language name.
    • source_lang (STRING, default auto) - auto for detection, or pin a specific code when detection misbehaves.

    One output: translated_text (STRING), which feeds straight into a text-concatenation node and then CLIPTextEncode - or anywhere else that takes a string.

    Installing it

    ComfyUI Manager is the easy path - search "ComfyUI-TranslationNode" and install. Otherwise:

    cd ComfyUI/custom_nodes
    git clone https://github.com/petr-pr/ComfyUI-TranslationNode
    cd ComfyUI-TranslationNode
    pip install -r requirements.txt
    

    requirements.txt pulls transformers>=4.41.0, sentencepiece, torch, and langdetect. Torch you already have; the transformers/sentencepiece pair is the real addition. Then comes the part the README is explicit about, because it's the part people skip: the model does not come with the pack. Download facebook/m2m100_418M from Hugging Face and drop it at:

    ComfyUI/models/translation/facebook/m2m100_418M/
    

    You're moving ~3.6 GB (the pytorch checkpoint is ~1.8 GB). After a restart you should see [TranslationNode] Using local model: models/translation/facebook/m2m100_418M in the console.

    Where people get burned

    The README's "will never download anything" promise only holds after you place the model. If the local path is missing, the code silently falls back to downloading from Hugging Face into the HF cache - which is the opposite of offline, and it's a 3.6 GB surprise on first run. Place the model manually before you rely on the privacy story.

    Second: this is a 418M-parameter model. On CPU it's fine for a sentence but sluggish for long blocks, and the first load eats over a gigabyte of RAM before caching kicks in. Keep the text reasonable and expect a slow first hit.

    Third, the ecosystem essay's old friend: dependency hell. Any node that also pins transformers versions can clash with this one since custom nodes share one Python environment. If another translation or LLM node misbehaves after this install, that's the suspect. And as with any custom node, glance at what you cloned - ComfyUI custom nodes run arbitrary code, and the community has been burned before. This one's short enough to read in a minute.

    It's a small, single-purpose node - but for the "my prompts, my machine, no cloud" crowd, it fills a real gap.

    CategoryText

    Inputs (3)

    NameTypeDefaultDescription
    textSTRINGEnter text to translate...β€”
    target_langSTRINGenβ€”
    source_langSTRINGautoβ€”

    Outputs (1)

    NameTypeDescription
    translated_textSTRINGβ€”