feat: Support for multiple translation services in tranbox
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
OPT_TRANS_TENCENT,
|
||||
OPT_LANGS_TO_CODE,
|
||||
OPT_LANGS_MAP,
|
||||
API_SPE_TYPES,
|
||||
} from "../config";
|
||||
import { browser } from "./browser";
|
||||
import {
|
||||
@@ -27,15 +28,11 @@ const langdetectFns = {
|
||||
* @param {*} text
|
||||
* @returns
|
||||
*/
|
||||
export const tryDetectLang = async (
|
||||
text,
|
||||
detectRemote = true,
|
||||
langDetector = OPT_TRANS_MICROSOFT
|
||||
) => {
|
||||
export const tryDetectLang = async (text, langDetector = "-") => {
|
||||
let deLang = "";
|
||||
|
||||
// 远程识别
|
||||
if (detectRemote && langDetector) {
|
||||
if (API_SPE_TYPES.detector.has(langDetector)) {
|
||||
try {
|
||||
const lang = await langdetectFns[langDetector](text);
|
||||
if (lang) {
|
||||
|
||||
@@ -849,14 +849,9 @@ export class Translator {
|
||||
// 提前进行语言检测
|
||||
let deLang = "";
|
||||
const { fromLang = "auto", toLang } = this.#rule;
|
||||
const { detectRemote, skipLangs = [] } = this.#setting;
|
||||
const { langDetector, skipLangs = [] } = this.#setting;
|
||||
if (fromLang === "auto") {
|
||||
const { langDetector } = this.#setting;
|
||||
deLang = await tryDetectLang(
|
||||
node.textContent,
|
||||
detectRemote,
|
||||
langDetector
|
||||
);
|
||||
deLang = await tryDetectLang(node.textContent, langDetector);
|
||||
if (
|
||||
deLang &&
|
||||
(toLang.slice(0, 2) === deLang.slice(0, 2) ||
|
||||
|
||||
Reference in New Issue
Block a user