feat: add new google translate api (issue: 225, by: Bush2021)

This commit is contained in:
Gabe
2025-06-27 19:29:00 +08:00
parent d22e3838c4
commit 51f58d095a
4 changed files with 35 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
import queryString from "query-string";
import {
OPT_TRANS_GOOGLE,
OPT_TRANS_GOOGLE2,
OPT_TRANS_MICROSOFT,
OPT_TRANS_DEEPL,
OPT_TRANS_DEEPLFREE,
@@ -80,6 +81,20 @@ const genGoogle = ({ text, from, to, url, key }) => {
return [input, init];
};
const genGoogle2 = ({ text, from, to, url, key }) => {
const body = JSON.stringify([[ [text], from, to ], "wt_lib"]);
const init = {
method: "POST",
headers: {
"Content-Type": "application/json+protobuf",
"X-Goog-API-Key": key,
},
body,
};
return [url, init];
};
const genMicrosoft = async ({ text, from, to }) => {
const [token] = await msAuth();
const params = {
@@ -440,6 +455,8 @@ export const genTransReq = ({ translator, text, from, to }, apiSetting) => {
switch (translator) {
case OPT_TRANS_GOOGLE:
return genGoogle(args);
case OPT_TRANS_GOOGLE2:
return genGoogle2(args);
case OPT_TRANS_MICROSOFT:
return genMicrosoft(args);
case OPT_TRANS_DEEPL: