PromptBaiduFanyiToText
Better translations, if you'll accept an API key and the cloud
- STRING
The online alternative to the local translator
The other two nodes in this pack translate on your machine with Helsinki OPUS-MT models. PromptBaiduFanyiToText is the opposite play: it calls Baidu's machine translation API over the internet. The author's own words (in the Chinese README, which is fuller than the English one) are that Baidu translates better and faster than the local models. Given that the local models are a ten-pair hardcoded list, that's not a hard bar to clear - the API supports 25 source languages including auto detection, which the offline path simply can't match.
The catch is the trade you're making. Your prompt text leaves your machine and hits Baidu's servers, and you need a Baidu developer account to get an appid and secretkey. If you're already fine with that (or you're in a region where Baidu is the convenient option), this is the node that actually handles arbitrary languages.
How it works
It implements Baidu's standard translation API flow: build an MD5 signature from appid + prompt + salt + secretkey, POST to api.fanyi.baidu.com/api/trans/vip/translate, and pull trans_result[0].dst out of the JSON response. The signature math is done for you - you only supply the credentials. Note that the target language is hardcoded to English (to=en), so the from_lang dropdown only picks the source. Output is always an English prompt, which is exactly what SDXL-lineage models want.
To get keys, the author points to Baidu's developer docs at https://fanyi-api.baidu.com/doc/12. Registration is free with a rate-limited tier - fine for occasional prompt translation, less so if you're batch-translating thousands of prompts.
The inputs
Four required fields, three of which are setup:
- appid and secretkey - your Baidu developer credentials. Both required; the node will not run without them.
- from_lang - source language dropdown. Defaults to
auto, which is what you want 95% of the time. The list covers the usual suspects:zh,yue,kor,th,pt,el,bul,fin,slo,cht,wyw,fra,ara,de,nl,est,cs,swe,jp,spa,ru,it,pl,ja. - prompt_text - the multiline string you actually translate.
Output is a single STRING with the English translation, which wires straight into a CLIP Text Encode's text input like any other text node.
Installing it
Same pack, same steps as the offline nodes:
cd ComfyUI/custom_nodes
git clone https://github.com/AIGCTeam/ComfyUI_kkTranslator_nodes
python -m pip install -r requirements.txt
Restart, or just search ComfyUI_kkTranslator_nodes in ComfyUI Manager. Dependencies are just torch, transformers, requests - the heavy lifting here happens at Baidu's end, not yours.
The gotchas
Three real ones.
First, the empty-credential error is a lie in the worst way. The code does raise "Please input your appid and secretkey" - and raising a plain string isn't valid in Python 3, so instead of a friendly message you get a red stack trace about exceptions needing to derive from BaseException. The intent is clear; the implementation just trips over itself. If you run it without keys and see a confusing error, that's what happened.
Second, your keys live in the node's fields, not an environment variable. That means if you share your workflow JSON or export it into an image, you're sharing your Baidu credentials with whoever opens it. Generate a workflow-specific key if the API lets you, and scrub before sharing.
Third, the endpoint is plain http, not https - visible right in the source. It's Baidu's own API so it's not a vulnerability you can fix from your side, but it's a slightly uncomfortable fact given your prompt text is traveling over it. Between that and the cloud round-trip, the offline Marian path starts looking pretty good for anything you'd rather keep local. The API node's real niche is languages the pack's hardcoded checkpoint list can't handle at all.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| appid | STRING | — | |
| secretkey | STRING | — | |
| from_lang | COMBO | auto | 25 options: auto, zh, yue, kor, th, pt, +19 |
| prompt_text | STRING | 你好 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |