feat: move 'remote detect' from rule to setting

This commit is contained in:
Gabe
2025-09-30 01:38:07 +08:00
parent 20c4d6f6eb
commit b60b770ed6
8 changed files with 62 additions and 63 deletions

View File

@@ -29,13 +29,13 @@ const langdetectFns = {
*/
export const tryDetectLang = async (
text,
useRemote = "false",
detectRemote = true,
langDetector = OPT_TRANS_MICROSOFT
) => {
let deLang = "";
// 远程识别
if (useRemote === "true" && langDetector) {
if (detectRemote && langDetector) {
try {
const lang = await langdetectFns[langDetector](text);
if (lang) {

View File

@@ -1,7 +1,6 @@
import { matchValue, type, isMatch } from "./utils";
import {
GLOBAL_KEY,
REMAIN_KEY,
OPT_STYLE_ALL,
OPT_LANGS_FROM,
OPT_LANGS_TO,
@@ -80,7 +79,7 @@ export const matchRule = async (href, { injectRules, subrulesList }) => {
"transTag",
"transTitle",
"transSelected",
"detectRemote",
// "detectRemote",
// "fixerFunc",
].forEach((key) => {
if (rule[key] === undefined || rule[key] === GLOBAL_KEY) {
@@ -88,9 +87,9 @@ export const matchRule = async (href, { injectRules, subrulesList }) => {
}
});
if (!rule.skipLangs || rule.skipLangs.length === 0) {
rule.skipLangs = globalRule.skipLangs;
}
// if (!rule.skipLangs || rule.skipLangs.length === 0) {
// rule.skipLangs = globalRule.skipLangs;
// }
if (rule.textStyle === GLOBAL_KEY) {
rule.textStyle = globalRule.textStyle;
rule.bgColor = globalRule.bgColor;
@@ -155,8 +154,8 @@ export const checkRules = (rules) => {
transTag,
transTitle,
transSelected,
detectRemote,
skipLangs,
// detectRemote,
// skipLangs,
// fixerSelector,
// fixerFunc,
transStartHook,
@@ -188,8 +187,8 @@ export const checkRules = (rules) => {
transTag: matchValue([GLOBAL_KEY, "span", "font"], transTag),
transTitle: matchValue([GLOBAL_KEY, "true", "false"], transTitle),
transSelected: matchValue([GLOBAL_KEY, "true", "false"], transSelected),
detectRemote: matchValue([GLOBAL_KEY, "true", "false"], detectRemote),
skipLangs: type(skipLangs) === "array" ? skipLangs : [],
// detectRemote: matchValue([GLOBAL_KEY, "true", "false"], detectRemote),
// skipLangs: type(skipLangs) === "array" ? skipLangs : [],
// fixerSelector: type(fixerSelector) === "string" ? fixerSelector : "",
transStartHook: type(transStartHook) === "string" ? transStartHook : "",
transEndHook: type(transEndHook) === "string" ? transEndHook : "",

View File

@@ -740,12 +740,8 @@ export class Translator {
// 提前进行语言检测
let deLang = "";
const {
detectRemote,
fromLang = "auto",
toLang,
skipLangs = [],
} = this.#rule;
const { fromLang = "auto", toLang } = this.#rule;
const { detectRemote, skipLangs = [] } = this.#setting;
if (fromLang === "auto") {
const { langDetector } = this.#setting;
deLang = await tryDetectLang(