Skip to content

Commit

Permalink
feat: 支持deeplx
Browse files Browse the repository at this point in the history
  • Loading branch information
Pylogmon committed Mar 20, 2023
1 parent 46e68d8 commit 101bdc5
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"http": {
"all": true,
"scope": [
"https://**"
"https://**",
"http://**"
]
},
"notification": {
Expand Down
55 changes: 55 additions & 0 deletions src/interfaces/deeplx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { fetch } from '@tauri-apps/api/http';
import { get } from "../global/config"

// 必须向外暴露info
export const info = {
// 接口中文名称
name: "DeepLX",
// 接口支持语言及映射
supportLanguage: {
"auto": "auto",
"zh-tw": "ZH",
"zh-cn": "ZH",
"de": "DE",
"en": "EN",
"es": "ES",
"fr": "FR",
"ja": "JA",
"ru": "RU",
},
// 接口需要配置项
needs: {
"deeplx_url": "DeepLX请求地址"
}
}
//必须向外暴露translate
export async function translate(text, from, to) {
// 获取语言映射
const { supportLanguage } = info;
// 获取设置项
const url = get('deeplx_url', '');
if (url == "") {
return '请先配置请求地址'
}
if (!(from in supportLanguage) || !(to in supportLanguage)) {
return '该接口不支持该语言'
}
const res = await fetch(`http://${url}/translate`, {
method: 'POST',
body: {
type: 'Json',
payload: {
source_lang: supportLanguage[from],
target_lang: supportLanguage[to],
text: text
}
}
})
if (res.ok) {
return res.data['data']
} else {
return res.status
}

}

4 changes: 3 additions & 1 deletion src/interfaces/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as _openai_code from './openai_code'
import * as _tencent from './tencent'
import * as _volcengine from './volcengine'
import * as _google from './google'
import * as _deeplx from './deeplx'

export const baidu = _baidu
export const caiyun = _caiyun
Expand All @@ -18,4 +19,5 @@ export const openai_summary = _openai_summary
export const openai_code = _openai_code
export const tencent = _tencent
export const volcengine = _volcengine
export const google = _google
export const google = _google
export const deeplx = _deeplx

0 comments on commit 101bdc5

Please sign in to comment.