Skip to content

DeepL Free translate API for Serverless, No TOKEN Required | DeepL 免费翻译API 无服务器函数部署,无需token

License

Notifications You must be signed in to change notification settings

guobao2333/DeepLX-Serverless

Repository files navigation

DeepLX Serverless

本项目是一个基于 DeepL翻译API 的无服务器函数部署项目,旨在提供一个可直接对接的免费翻译解决方案,很适合需要在无服务器环境中集成DeepL翻译服务的开发者使用。

与原项目DeepLX的区别在于利用了无服务器函数(边缘函数)请求IP不固定的特性,有效避免了Error 429请求太频繁的报错(不过嘛凡事总有例外¯\_(ツ)_/¯)

虽然因此不会立马被暂时封禁,但也请不要滥用!目前我部署在vercel上会有流量限制,如果您有大量内容需要翻译,请购买DeepL的付费版,当前项目使用的free接口会受到DeepL政策限制
由于目前项目未对pro接口进行适配,所以现在还只能使用free接口,不过在将来会完善,敬请期待~ („• ֊ •„)੭

如果本项目对你有用的话,不妨点个Star❤️
Click Star if you like!! thanks❤️

Prerequisites | 你需要准备什么

在正式开始使用前,我们还需要做一些准备工作呢 (^o^)/
你需要:

  • 一双灵活的小手🙌🏻
  • 一个聪明的小脑袋瓜🧠
  • 支持 Nodejs ≥18DockerServerless Function 的服务器💻
  • (可选) 拥有VercelNetlify的账号

Deploy | 部署

使用任意支持无服务器函数部署的服务器,比如可以使用 Vercel 或者 Netlify 进行部署,又或者其他能够使用nodejs的服务器。(大多数服务器提供商都提供函数计算服务器)

如果你拥有Vercel账号的话那就很简单了,因为你只需要点击下方按钮即可一键部署到Vercel:

Deploy with Vercel

或者你拥有Netlify账号的话,也可以一键部署到Netlify:

Deploy to Netlify

因维护者我有多个仓库需要维护,短时间内将无法对多平台部署方案进行兼容,您可以打开一个issues📌或打开一个Pull Request📎贡献您的代码。
✨项目当前没有任何需要填写的变量值,但在后续可能会添加。

Docker | 容器部署

🐳直接运行预构建容器:

docker run -d -p 9000:9000 ghcr.io/guobao2333/deeplx-serverless

🚧你还可以自己构建后运行:

docker build -t deeplxs .
docker run -d -p 9000:9000 deeplxs

Self hosting | 源码部署

✅尽管本项目是专为 serverless 适配的方案,但是也能使用自己的服务器直接部署源码:

git clone https://github.com/guobao2333/DeepLX-Serverless
cd DeepLX-Serverless
npm i
npm run start

📋直接复制到命令行运行:

git clone https://github.com/guobao2333/DeepLX-Serverless && cd DeepLX-Serverless && npm i && npm run start

🛠️你可以运行npm run test用来测试翻译接口。
⚠️注意!测试命令仅返回翻译内容,获取所有结果需要使用POST

如果部署完成了,就可以开始使用啦!🎉

startup parameters | 启动参数

Important

此功能在 v2.0.0 及以上版本中可用

如果你想的话,可以在启动时添加参数。
添加一个--no前缀来禁止备选翻译:

npm run start -- --no-a

💡使用-h来获取所有参数。

How To Use | 如何使用

Important

请求时视部署服务的地区而定,可能会存在返回速度不一的情况,在中国地区可能会出现完全无法访问的情况,届时请尝试更换部署服务的地区,或让您部署的服务能够正常向DeepL发送请求即可。

📡使用post通过 域名地址 + /translate + json请求体 这样的形式获取json响应。

❔详细API文档,请查看本项目的wiki:
English | 简体中文

📋你可以直接复制到命令行运行本地测试:

curl --location --request POST 'http://localhost:9000/translate' --header 'Content-Type: application/json' --data '{"text": "你好,世界!", "source_lang": "zh", "target_lang": "en"}'

✨部署完成后,建议搭配浏览器插件「沉浸式翻译」一同使用。

Use In Browser Extension Plugin | 在沉浸式翻译中使用

  1. 在浏览器上安装最新的 沉浸式翻译
  2. 点击左下角的 "开发者设置"。启用测试版实验功能。
  3. 翻译服务选中 DeepLX(beta)
  4. 设置 URL 为刚才获取的访问路径(需带translate)。

沉浸式翻译

Star History

Star History Chart

Contribute | 贡献

Important

在您做出贡献之前请先阅读理解并遵守以下内容:

  1. 先切换到dev分支,同步最新代码。
  2. 如果在贡献时对贡献规范有疑惑,请打开一个issues
  3. 不要对相同代码进行多次拉取请求!!

本人因时间(和各种各样的)原因,故无法及时对您的贡献进行测试,所以您可能还需要自行测试

如果你是第一次贡献,并且真的想贡献点什么,那么请查看《如何为开源做贡献》,不过我喜欢叫它「开源贡献指南」,那里有你需要知道的一切。

License | 开源许可

本项目遵循GNU/AGPLv3许可证的条款发布。

DeepL free translate API for Serverless
Copyright (C) 2024 shiguobaona

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

Acknowledgments | 鸣谢

  1. OwO-Network/DeepLX - 感谢OwO-Network的优秀项目(•̀ᴗ•́)و̑̑
  2. LegendLeo/deeplx-serverless - 原项目
  3. bropines/Deeplx-vercel - 参考部分实现