Skip to content

Commit

Permalink
📝 doc: 更新README及项目信息
Browse files Browse the repository at this point in the history
  • Loading branch information
LegendLeo committed Jan 11, 2024
1 parent 68bf7c9 commit 4e2b0aa
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ lerna-debug.log*
node_modules/

yarn.lock
package-lock.json
package-lock.json

dist.zip
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 LegendLeo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
91 changes: 91 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# DeepLX Serverless

DeepLX 免费翻译API**腾讯云函数部署版**,与[原项目DeepLX](https://github.com/OwO-Network/DeepLX)的区别在于**利用了云函数的请求IP不固定的特性,极大程度上避免了`429`请求太频繁报错**

感谢原项目[OwO-Network/DeepLX](https://github.com/OwO-Network/DeepLX)提供的灵感,这是本项目的坚实基础

## Usage | 用法

### Prerequisites | 你需要准备什么

- 一台电脑或平板
- 一个腾讯旗下的账号或者手机号

### Deploy | 部署

[https://cloud.tencent.com/](https://cloud.tencent.com/) 注册账号

进入云函数控制台:[https://console.cloud.tencent.com/scf/list](https://console.cloud.tencent.com/scf/list)

依次点击【新建】->【从头开始】,然后按照以下配置,**没写出来的就不用管,使用默认设置**

- 函数类型:Web函数
- 函数名称:deeplx(名字随便取)
- 地域:任意(国内也可直连)
- 运行环境:Nodejs 16.13(或者更高的版本)
- 高级配置:
- 内存:64M
- 执行超时时间:60 秒
- 请求多并发:5 并发(个人体验下来,2个都行)
- 日志配置 -> 日志投递:启用(可以选择不开,开的话一个月应该几分钱)
- 函数代码:本地上传zip包([点我下载 ZIP 包](https://github.com/LegendLeo/deeplx-serverless/releases/download/v1.0.0/dist.zip)
- 触发器配置(这里可能要创建一个新的触发器):
- 默认触发器
- 触发别名/版本:默认流量
- 请求方法:ANY
- 发布环境:发布
- 鉴权方法:免鉴权

此时已部署完成,可以点击“完成”按钮,进入【函数管理】,点击【函数代码】,往下拉,找到【访问路径】并复制后续使用


### How to use | 如何使用

建议搭配浏览器插件沉浸式翻译一同使用,使用的时候需要把访问路径里的 `/release` 部分替换为翻译路径`translate`

例如:`https://service-aaaaa.gz.apigw.tencentcs.com/release/` 改为:`https://service-aaaaa.gz.apigw.tencentcs.com/translate`

请求示例:

``` bash
curl --location 'https://service-aaaaa.gz.apigw.tencentcs.com/translate' \
--header 'Content-Type: application/json' \
--data '{
"text": "你好,世界",
"source_lang": "zh",
"target_lang": "en"
}'
```

响应示例:

``` json
{
"code": 200,
"message": "success",
"data": "Hello, world.",
"source_lang": "zh",
"target_lang": "en",
"alternatives": ["Hello, World.", "Hello, world!", "Hi, world."]
}
```

#### 沉浸式翻译设置

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

![沉浸式翻译](https://github.com/LegendLeo/deeplx-serverless/assets/25115173/d3affe2b-9e99-4d5c-bc8c-cd67e70d0368)

## 自托管

尽管本项目是专为 serverless 适配的方案,但是也能使用自己提供服务器进行部署

``` bash
git clone https://github.com/LegendLeo/deeplx-serverless
cd deeplx-serverless
npm install
npm run start
```
19 changes: 12 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
{
"name": "deepl",
"name": "deeplx-serverless",
"version": "1.0.0",
"description": "",
"main": "index.js",
"description": "DeepLX Free API for serverless",
"main": "translate.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"start": "node server.js",
"zip": "zip -r dist.zip ./"
},
"keywords": [],
"author": "",
"license": "ISC",
"keywords": [
"deeplx",
"deepl",
"translate",
"serverless"
],
"license": "MIT",
"dependencies": {
"axios": "^1.6.3",
"body-parser": "^1.20.2",
Expand Down

0 comments on commit 4e2b0aa

Please sign in to comment.