ComfyUI Node

Text Translate

One translation node, three backends — this is the one the pack wants you to use

By chflame163·Created 3 years ago·Updated about a year ago· 60
Text Translate
    • STRING
    text
    Translate_to_languageen
    API

    TextTranslate is the node this pack has been building toward. chflame163's ComfyUI_BaiduTranslate started life as two separate translation nodes - a keyed Baidu API node and a no-key scraper - and this one merges them into a single dropdown, then adds a third backend. The README is unambiguous: replace your old BaiduTrans(DevApi) and BaiduTrans(v2Trans) nodes with this one; the old ones will no longer be updated. If you're installing the pack fresh, this is the node you actually want.

    Why translate at all? Same reason as always: SD and Flux text encoders were trained on English, and a Chinese prompt degrades into garbled tokens. Translate it to English first and the encoder actually hears you. That's the whole point of the pack, and TextTranslate is its cleanest expression.

    How it works

    Same file, same HTTP calls as the old nodes - the only difference is that the API dropdown decides which backend runs:

    • Baidu developer API - the official keyed endpoint, same 1M-char free tier as before. The reliable one. Needs your appid + secret.
    • Baidu v2Trans API - the no-key scraper against fanyi.baidu.com. Zero setup, flaky at length, needs a JavaScript runtime (Node.js) installed for the signing step.
    • NiuTrans API - the new kid. A third translation service (niutrans.com); you apply there for a text-translation API key and drop it into apikey.json's niutrans_apikey field.

    How to choose: got a Baidu dev key (or don't mind registering for one) → use the developer API. Want zero setup and accept flakiness → v2Trans. NiuTrans is the escape hatch when Baidu's quota or the scraper let you down - just remember it's a second key to manage, not a no-key option.

    Inputs and output

    Three required inputs:

    • text - your Chinese or English text, multiline.
    • Translate_to_language - en or zh, default en. You'll mostly want en (Chinese prompt in, English prompt out).
    • API - the backend selector above.

    Output is a single STRING, so it drops into the same places the old nodes did: a CLIPTextEncode text port, a prompt concatenator, or a preview node if you want to read the translation (the pack has no built-in preview - the author points you at the AlekPet Preview Text node for that).

    Installing and configuring

    Manager search "ComfyUI_BaiduTranslate", or the manual route:

    cd ComfyUI/custom_nodes
    git clone https://github.com/chflame163/ComfyUI_BaiduTranslate
    cd ComfyUI_BaiduTranslate
    pip install -r requirements.txt   # requests + pyexecjs
    

    Restart and you're done. All three keys live in one file, apikey.json - and this is the one place the pack reliably bites people. The old README section tells you to edit baidu_devapi.json, but the code never reads that file; it only ever reads apikey.json. The README's own new-node section tells you to migrate your old Baidu values over. It should look like:

    {"baidu_dev_appid": "your_appid", "baidu_dev_appkey": "your_secret", "niutrans_apikey": "your_niutrans_key"}
    

    Missing or empty keys don't throw - the node just returns error! as the translation. That's your diagnostic. If you pick "Baidu developer API" or "NiuTrans API" and get error!, the key isn't in apikey.json. If you pick v2Trans and get a JS runtime error, install Node.js. Quota exhausted on the Baidu dev tier shows up the same way.

    Bottom line

    If one node from this pack goes in your workflow, it's this one: the future-proof path, three backends, and the author's explicit recommendation. The scraper backend is fine for quick drafts, the keyed backends are the ones you'll actually rely on - and now you don't need three different nodes to switch between them.

    Category😺dzNodes/BaiduTranslate

    Inputs (3)

    NameTypeDefaultDescription
    textSTRING
    Translate_to_languageCOMBOen2 options: en, zh
    APICOMBO3 options: Baidu developer API, Baidu v2Trans API, NiuTrans API

    Outputs (1)

    NameTypeDescription
    STRINGSTRING