Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持 DeepL 官方 API 接口响应格式 #99

Closed
tisfeng opened this issue Mar 20, 2024 · 5 comments
Closed

支持 DeepL 官方 API 接口响应格式 #99

tisfeng opened this issue Mar 20, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@tisfeng
Copy link
Contributor

tisfeng commented Mar 20, 2024

目前 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
Copy link
Member

missuo commented Mar 20, 2024

必须可以,这很容易!我甚至都不用处理官方的 Response,美国东部时间今天晚上之前我会推送一个版本支持这一点。 @tisfeng

@missuo
Copy link
Member

missuo commented Mar 20, 2024

你想要兼容的是 DeepL 官方 Free API 的 Response 吗,那可能和 iOS 客户端的 Response 是有差别的,我得转换一下,但是问题不大。

@missuo missuo added the enhancement New feature or request label Mar 20, 2024
@tisfeng
Copy link
Contributor Author

tisfeng commented Mar 20, 2024

是的,只要支持 DeepL 官方 API 的接口格式就好,这样类似 Easydict 应用就能很方便将 DeepLX 接口当作官方 API 使用了。

非常感谢!

@missuo
Copy link
Member

missuo commented Mar 20, 2024

Released v0.9.1.

@missuo missuo closed this as completed Mar 20, 2024
@tisfeng
Copy link
Contributor Author

tisfeng commented Mar 21, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants