A lightweight translation service deployed on Cloudflare Workers. After deployment, you can call a single HTTP API to translate text with DeepLX.
- Single translation endpoint:
POST /hi/translate - Supports automatic source language detection with
sourceLang = auto - Returns translated text together with alternative results and language info
- Home page:
/ - Translation API:
/hi/translate
Install dependencies:
npm installInstall Wrangler and log in to Cloudflare:
npm install -g wrangler
wrangler loginDeploy the Worker:
npm run deployHeaders:
Content-Type: application/json
Authorization: Bearer <TOKEN>Authentication:
bearerAuth1is the bearer-token auth middleware used bysrc/index.ts- Send
Authorization: Bearer <TOKEN>whenTOKENis configured in the Worker environment - If
TOKENis not configured,bearerAuth1allows requests without authentication
Body:
{
"sourceLang": "auto",
"targetLang": "ZH",
"text": "Hello world"
}Fields:
sourceLang: source language such asEN,ZH,JA,KO, orautotargetLang: target language such asEN,ZHtext: the text you want to translate
Success:
{
"code": 200,
"id": 123456000,
"data": "你好,世界",
"alternatives": ["你好世界", "世界你好"],
"source_lang": "EN",
"target_lang": "ZH",
"method": "Free"
}Failure:
{
"code": 503,
"message": "Translation failed"
}curl -X POST https://your-worker-domain/hi/translate \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-token" \
-d '{
"sourceLang": "auto",
"targetLang": "ZH",
"text": "Hello world"
}'- The public API is
POST /hi/translate bearerAuth1checks theAuthorization: Bearer <TOKEN>header whenTOKENis configuredsourceLang=autouses a simple built-in heuristic- Frequent requests may trigger rate limiting or temporary blocking from DeepL
- This project depends on the availability of the DeepL web endpoint, so upstream changes may break it
MIT