detect lang remote

This commit is contained in:
Gabe Yuan
2023-10-10 18:03:05 +08:00
parent 5af66204c4
commit 5cd6977a6e
5 changed files with 77 additions and 6 deletions

View File

@@ -10,6 +10,8 @@ import {
PROMPT_PLACE_FROM,
PROMPT_PLACE_TO,
KV_SALT_SYNC,
URL_BAIDU_LANGDETECT,
OPT_LANGS_BAIDU,
} from "../config";
import { tryDetectLang } from "../libs";
import { sha256 } from "../libs/utils";
@@ -237,6 +239,30 @@ const apiCustomTranslate = async (
return [trText, isSame];
};
/**
* 百度语言识别
* @param {*} text
* @returns
*/
export const apiBaiduLangdetect = async (text) => {
const res = await fetchPolyfill(URL_BAIDU_LANGDETECT, {
headers: {
"Content-type": "application/json",
},
method: "POST",
body: JSON.stringify({
query: text,
}),
useCache: true,
});
if (res.error === 0) {
return OPT_LANGS_BAIDU.get(res.lan) ?? res.lan;
}
return "";
};
/**
* 统一翻译接口
* @param {*} param0