Nodes/ComfyUI-keitNodes/M2MTranslator
ComfyUI Node

M2MTranslator

Translate prompts inside ComfyUI — no API key, no cloud, just a real model

By keit0728·Created about a year ago·Updated about a year ago· 3
M2MTranslator
    • translated_text
    • detected_language
    • confidence
    textこんにちは、世界
    source_languageauto_detect
    target_languageen
    model_size418M
    deviceauto
    num_beams5

    The name is not a lie and it's the best thing about it: this is a real, local translation model, not a wrapper around some API. M2MTranslator runs Meta's M2M-100 (Many-to-Many 100) inside your graph and will translate between 80 listed languages with no key, no account, no per-token bill. You hit the first translation, a few gigabytes of model download, and then it's yours forever.

    Why would you reach for it? Prompt translation is a genuinely common workflow headache. You've got a Japanese source prompt and an English-finetuned model, or a LoRA trained on Chinese tags and you want to port a workflow to it, or you're batch-generating captions for a multilingual dataset. Doing that in a browser tab works, but doing it in the graph means it's reproducible - the translation becomes part of the workflow JSON you share, and it can chain straight into a CLIPTextEncode.

    How it works

    Under the hood it loads facebook/m2m100_418M or the bigger facebook/m2m100_1.2B through Hugging Face Transformers. Pick a model_size - the 418M is the sane default; the 1.2B translates more fluently but eats more VRAM. On CUDA it loads in fp16, on CPU in fp32, and device lets you force either (or leave it on auto).

    Three things matter in the inputs:

    • source_language - defaults to auto_detect, which uses the langid library to guess the language. Set it explicitly if you know it; auto-detect on short strings is famously hit-or-miss.
    • target_language - the output language. That's the one you'll actually change day to day.
    • num_beams - beam search width, 1–10, default 5. Higher = better quality but slower; drop it to 1–2 for speed when you don't care about polish.

    Outputs: translated_text (a plain STRING you can wire into a prompt box), plus detected_language and a confidence FLOAT from langid's guess. The detected language is worth piping to a debug display - if auto-detect guessed wrong, that's why the output is weird.

    The gotchas that will actually bite you

    • First run downloads a multi-GB model. It goes to ComfyUI/models/keit-nodes/ (split into m2m100_418M / m2m100_1.2B), not through the Manager. Be patient on a slow connection.
    • The 1.2B on CPU is painful. A sentence can take tens of seconds. If you're CPU-only, stay on 418M.
    • Switching model size or device triggers a full reload. The node caches models at the class level so multiple instances share one copy, but flip 418M1.2B and you'll watch it reload. Decide your size once.
    • langid misdetects short text - a two-word prompt can come back as the wrong language. When in doubt, set source_language manually.
    • Same-language short-circuit: if detected source equals target, it returns the text unchanged. That's a feature, not a bug - but it means a misdetection silently does nothing instead of failing loudly.

    Install

    It's part of ComfyUI-keitNodes. The easy path is the Manager - search "ComfyUI-keitNodes" and hit install. Manual:

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

    The pack's requirements.txt is just langid and huggingface-hub - Transformers and torch come from ComfyUI's own environment, so don't be surprised there's no giant pip install. Restart, then the model downloads on first translation.

    This is the one genuinely heavy node in an otherwise featherweight pack. Treat it as a tool you reach for when a workflow crosses a language boundary, not something to drop into every graph - and if you're only resizing images, skip it entirely.

    CategorykeitNodes

    Inputs (6)

    NameTypeDefaultDescription
    textSTRINGこんにちは、世界
    source_languageCOMBOauto_detect81 options: auto_detect, ja, en, zh, ko, fr, +75
    target_languageCOMBOen80 options: ja, en, zh, ko, fr, de, +74
    model_sizeCOMBO418M2 options: 418M, 1.2B
    deviceCOMBOauto3 options: auto, cpu, cuda
    num_beamsoptINT51–10

    Outputs (3)

    NameTypeDescription
    translated_textSTRING
    detected_languageSTRING
    confidenceFLOAT