Skip to content

Commit

Permalink
fix: 修复谷歌翻译设置项读取失败及语言错误问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Pylogmon committed Mar 11, 2023
1 parent d818f8f commit f2bc4f6
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/interfaces/google.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const info = {
supportLanguage: {
"auto": "auto",
"zh-cn": "zh_CN",
"zh-tw":"zh-TW",
"zh-tw": "zh-TW",
"ja": "ja",
"en": "en",
"ko": "ko",
Expand All @@ -17,27 +17,29 @@ export const info = {
"de": "de"
},
needs: {
"google_proxy": "谷歌翻译镜像地址(http(s)://translate.xxx.xxx)"
"google_proxy": "谷歌翻译镜像(eg:translate.google.com)"
}
}

export async function translate(text, from, to) {
const { supportLanguage } = info;
if (!(from in supportLanguage) || !(to in supportLanguage)) {
return '该接口只支持中英互译'
return '该接口不支持该语言'
}

const domain = get('google_proxy', "https://translate.google.com");

let res = await fetch(`${domain}/translate_a/single`, {
let domain = get('google_proxy', "translate.google.com");
if (domain == '') {
domain = "translate.google.com"
}
let res = await fetch(`https://${domain}/translate_a/single`, {
method: 'GET',
timeout: 5,
query: {
"client": "at",
"sl": from,
"tl": to,
"dt":"t",
"q":text
"sl": supportLanguage[from],
"tl": supportLanguage[to],
"dt": "t",
"q": text
}
});
if (res.status == 200) {
Expand All @@ -50,5 +52,5 @@ export async function translate(text, from, to) {
else {
return "请求过于频繁,请求失败!"
}

}

0 comments on commit f2bc4f6

Please sign in to comment.