detect lang remote
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user