支持 DeepL 官方 API 接口响应格式
Closed this issue · 5 comments
tisfeng commented
目前 DeepLX 似乎只支持 JSON 请求格式,并且响应格式和官方 API 不同,希望能提供一个类似 v2/translate 接口,支持 URL-encoded 格式,并且返回数据能兼容官方 API,这样能更方便接口在各种第三方平台使用。
参见 tisfeng/Easydict#464 (comment)
curl -X POST http://localhost:1188/translate?token=your_access_token \
-H "Content-Type: application/json" \
-d '{
"text": "Hello, world!",
"source_lang": "EN",
"target_lang": "ZH"
}'
响应结果:
{
"alternatives": [
"世界,你好",
"你好,世界!",
"大家好"
],
"code": 200,
"data": "你好,世界",
"id": 8376425010,
"method": "Free",
"source_lang": "NL",
"target_lang": "ZH"
}
DeepL 官方 API
curl -X POST 'https://api-free.deepl.com/v2/translate' \
--header 'Authorization: DeepL-Auth-Key [yourAuthKey]' \
--data-urlencode 'text=Hello, world!' \
--data-urlencode 'target_lang=DE'
响应结果:
{
"translations": [
{
"detected_source_language": "EN",
"text": "Hallo, Welt!"
}
]
}
missuo commented
你想要兼容的是 DeepL 官方 Free API 的 Response 吗,那可能和 iOS 客户端的 Response 是有差别的,我得转换一下,但是问题不大。
tisfeng commented
赞