feat: move 'remote detect' from rule to setting
This commit is contained in:
@@ -1033,6 +1033,11 @@ export const I18N = {
|
|||||||
en: `After enabling, the detection accuracy will increase, but it will reduce the translation speed. Please enable it as appropriate.`,
|
en: `After enabling, the detection accuracy will increase, but it will reduce the translation speed. Please enable it as appropriate.`,
|
||||||
zh_TW: `啟用後可提升偵測準確度,但會降低翻譯速度,請視需要開啟。`,
|
zh_TW: `啟用後可提升偵測準確度,但會降低翻譯速度,請視需要開啟。`,
|
||||||
},
|
},
|
||||||
|
detect_lang_service: {
|
||||||
|
zh: `语言检测服务`,
|
||||||
|
en: `Language detect service`,
|
||||||
|
zh_TW: `語言檢測服務`,
|
||||||
|
},
|
||||||
disable: {
|
disable: {
|
||||||
zh: `禁用`,
|
zh: `禁用`,
|
||||||
en: `Disable`,
|
en: `Disable`,
|
||||||
|
|||||||
@@ -96,8 +96,8 @@ export const DEFAULT_RULE = {
|
|||||||
transTag: GLOBAL_KEY, // 译文元素标签
|
transTag: GLOBAL_KEY, // 译文元素标签
|
||||||
transTitle: GLOBAL_KEY, // 是否同时翻译页面标题
|
transTitle: GLOBAL_KEY, // 是否同时翻译页面标题
|
||||||
transSelected: GLOBAL_KEY, // 是否启用划词翻译
|
transSelected: GLOBAL_KEY, // 是否启用划词翻译
|
||||||
detectRemote: GLOBAL_KEY, // 是否使用远程语言检测
|
// detectRemote: GLOBAL_KEY, // 是否使用远程语言检测 (移回setting)
|
||||||
skipLangs: [], // 不翻译的语言
|
// skipLangs: [], // 不翻译的语言 (移回setting)
|
||||||
// fixerSelector: "", // 修复函数选择器 (暂时作废)
|
// fixerSelector: "", // 修复函数选择器 (暂时作废)
|
||||||
// fixerFunc: GLOBAL_KEY, // 修复函数 (暂时作废)
|
// fixerFunc: GLOBAL_KEY, // 修复函数 (暂时作废)
|
||||||
transStartHook: "", // 钩子函数
|
transStartHook: "", // 钩子函数
|
||||||
@@ -132,8 +132,8 @@ export const GLOBLA_RULE = {
|
|||||||
transTag: DEFAULT_TRANS_TAG, // 译文元素标签
|
transTag: DEFAULT_TRANS_TAG, // 译文元素标签
|
||||||
transTitle: "false", // 是否同时翻译页面标题
|
transTitle: "false", // 是否同时翻译页面标题
|
||||||
transSelected: "true", // 是否启用划词翻译
|
transSelected: "true", // 是否启用划词翻译
|
||||||
detectRemote: "true", // 是否使用远程语言检测
|
// detectRemote: "true", // 是否使用远程语言检测 (移回setting)
|
||||||
skipLangs: [], // 不翻译的语言
|
// skipLangs: [], // 不翻译的语言 (移回setting)
|
||||||
// fixerSelector: "", // 修复函数选择器 (暂时作废)
|
// fixerSelector: "", // 修复函数选择器 (暂时作废)
|
||||||
// fixerFunc: "-", // 修复函数 (暂时作废)
|
// fixerFunc: "-", // 修复函数 (暂时作废)
|
||||||
transStartHook: "", // 钩子函数
|
transStartHook: "", // 钩子函数
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import {
|
|||||||
OPT_TRANS_MICROSOFT,
|
OPT_TRANS_MICROSOFT,
|
||||||
DEFAULT_API_LIST,
|
DEFAULT_API_LIST,
|
||||||
} from "./api";
|
} from "./api";
|
||||||
import { DEFAULT_OW_RULE } from "./rules";
|
|
||||||
|
|
||||||
// 默认快捷键
|
// 默认快捷键
|
||||||
export const OPT_SHORTCUT_TRANSLATE = "toggleTranslate";
|
export const OPT_SHORTCUT_TRANSLATE = "toggleTranslate";
|
||||||
@@ -128,7 +127,7 @@ export const DEFAULT_SETTING = {
|
|||||||
injectRules: true, // 是否注入订阅规则
|
injectRules: true, // 是否注入订阅规则
|
||||||
fabClickAction: 0, // 悬浮按钮点击行为
|
fabClickAction: 0, // 悬浮按钮点击行为
|
||||||
// injectWebfix: true, // 是否注入修复补丁(作废)
|
// injectWebfix: true, // 是否注入修复补丁(作废)
|
||||||
// detectRemote: false, // 是否使用远程语言检测(移至rule,作废)
|
detectRemote: false, // 是否使用远程语言检测 (从rule移回)
|
||||||
// contextMenus: true, // 是否添加右键菜单(作废)
|
// contextMenus: true, // 是否添加右键菜单(作废)
|
||||||
contextMenuType: 1, // 右键菜单类型(0不显示,1简单菜单,2多级菜单)
|
contextMenuType: 1, // 右键菜单类型(0不显示,1简单菜单,2多级菜单)
|
||||||
// transTag: DEFAULT_TRANS_TAG, // 译文元素标签(移至rule,作废)
|
// transTag: DEFAULT_TRANS_TAG, // 译文元素标签(移至rule,作废)
|
||||||
@@ -145,6 +144,7 @@ export const DEFAULT_SETTING = {
|
|||||||
blacklist: DEFAULT_BLACKLIST.join(",\n"), // 禁用翻译名单
|
blacklist: DEFAULT_BLACKLIST.join(",\n"), // 禁用翻译名单
|
||||||
csplist: DEFAULT_CSPLIST.join(",\n"), // 禁用CSP名单
|
csplist: DEFAULT_CSPLIST.join(",\n"), // 禁用CSP名单
|
||||||
// disableLangs: [], // 不翻译的语言(移至rule,作废)
|
// disableLangs: [], // 不翻译的语言(移至rule,作废)
|
||||||
|
skipLangs: [], // 不翻译的语言(从rule移回)
|
||||||
transInterval: 100, // 翻译等待时间
|
transInterval: 100, // 翻译等待时间
|
||||||
langDetector: OPT_TRANS_MICROSOFT, // 远程语言识别服务
|
langDetector: OPT_TRANS_MICROSOFT, // 远程语言识别服务
|
||||||
mouseHoverSetting: DEFAULT_MOUSE_HOVER_SETTING, // 鼠标悬停翻译
|
mouseHoverSetting: DEFAULT_MOUSE_HOVER_SETTING, // 鼠标悬停翻译
|
||||||
|
|||||||
@@ -29,13 +29,13 @@ const langdetectFns = {
|
|||||||
*/
|
*/
|
||||||
export const tryDetectLang = async (
|
export const tryDetectLang = async (
|
||||||
text,
|
text,
|
||||||
useRemote = "false",
|
detectRemote = true,
|
||||||
langDetector = OPT_TRANS_MICROSOFT
|
langDetector = OPT_TRANS_MICROSOFT
|
||||||
) => {
|
) => {
|
||||||
let deLang = "";
|
let deLang = "";
|
||||||
|
|
||||||
// 远程识别
|
// 远程识别
|
||||||
if (useRemote === "true" && langDetector) {
|
if (detectRemote && langDetector) {
|
||||||
try {
|
try {
|
||||||
const lang = await langdetectFns[langDetector](text);
|
const lang = await langdetectFns[langDetector](text);
|
||||||
if (lang) {
|
if (lang) {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { matchValue, type, isMatch } from "./utils";
|
import { matchValue, type, isMatch } from "./utils";
|
||||||
import {
|
import {
|
||||||
GLOBAL_KEY,
|
GLOBAL_KEY,
|
||||||
REMAIN_KEY,
|
|
||||||
OPT_STYLE_ALL,
|
OPT_STYLE_ALL,
|
||||||
OPT_LANGS_FROM,
|
OPT_LANGS_FROM,
|
||||||
OPT_LANGS_TO,
|
OPT_LANGS_TO,
|
||||||
@@ -80,7 +79,7 @@ export const matchRule = async (href, { injectRules, subrulesList }) => {
|
|||||||
"transTag",
|
"transTag",
|
||||||
"transTitle",
|
"transTitle",
|
||||||
"transSelected",
|
"transSelected",
|
||||||
"detectRemote",
|
// "detectRemote",
|
||||||
// "fixerFunc",
|
// "fixerFunc",
|
||||||
].forEach((key) => {
|
].forEach((key) => {
|
||||||
if (rule[key] === undefined || rule[key] === GLOBAL_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) {
|
// if (!rule.skipLangs || rule.skipLangs.length === 0) {
|
||||||
rule.skipLangs = globalRule.skipLangs;
|
// rule.skipLangs = globalRule.skipLangs;
|
||||||
}
|
// }
|
||||||
if (rule.textStyle === GLOBAL_KEY) {
|
if (rule.textStyle === GLOBAL_KEY) {
|
||||||
rule.textStyle = globalRule.textStyle;
|
rule.textStyle = globalRule.textStyle;
|
||||||
rule.bgColor = globalRule.bgColor;
|
rule.bgColor = globalRule.bgColor;
|
||||||
@@ -155,8 +154,8 @@ export const checkRules = (rules) => {
|
|||||||
transTag,
|
transTag,
|
||||||
transTitle,
|
transTitle,
|
||||||
transSelected,
|
transSelected,
|
||||||
detectRemote,
|
// detectRemote,
|
||||||
skipLangs,
|
// skipLangs,
|
||||||
// fixerSelector,
|
// fixerSelector,
|
||||||
// fixerFunc,
|
// fixerFunc,
|
||||||
transStartHook,
|
transStartHook,
|
||||||
@@ -188,8 +187,8 @@ export const checkRules = (rules) => {
|
|||||||
transTag: matchValue([GLOBAL_KEY, "span", "font"], transTag),
|
transTag: matchValue([GLOBAL_KEY, "span", "font"], transTag),
|
||||||
transTitle: matchValue([GLOBAL_KEY, "true", "false"], transTitle),
|
transTitle: matchValue([GLOBAL_KEY, "true", "false"], transTitle),
|
||||||
transSelected: matchValue([GLOBAL_KEY, "true", "false"], transSelected),
|
transSelected: matchValue([GLOBAL_KEY, "true", "false"], transSelected),
|
||||||
detectRemote: matchValue([GLOBAL_KEY, "true", "false"], detectRemote),
|
// detectRemote: matchValue([GLOBAL_KEY, "true", "false"], detectRemote),
|
||||||
skipLangs: type(skipLangs) === "array" ? skipLangs : [],
|
// skipLangs: type(skipLangs) === "array" ? skipLangs : [],
|
||||||
// fixerSelector: type(fixerSelector) === "string" ? fixerSelector : "",
|
// fixerSelector: type(fixerSelector) === "string" ? fixerSelector : "",
|
||||||
transStartHook: type(transStartHook) === "string" ? transStartHook : "",
|
transStartHook: type(transStartHook) === "string" ? transStartHook : "",
|
||||||
transEndHook: type(transEndHook) === "string" ? transEndHook : "",
|
transEndHook: type(transEndHook) === "string" ? transEndHook : "",
|
||||||
|
|||||||
@@ -740,12 +740,8 @@ export class Translator {
|
|||||||
|
|
||||||
// 提前进行语言检测
|
// 提前进行语言检测
|
||||||
let deLang = "";
|
let deLang = "";
|
||||||
const {
|
const { fromLang = "auto", toLang } = this.#rule;
|
||||||
detectRemote,
|
const { detectRemote, skipLangs = [] } = this.#setting;
|
||||||
fromLang = "auto",
|
|
||||||
toLang,
|
|
||||||
skipLangs = [],
|
|
||||||
} = this.#rule;
|
|
||||||
if (fromLang === "auto") {
|
if (fromLang === "auto") {
|
||||||
const { langDetector } = this.#setting;
|
const { langDetector } = this.#setting;
|
||||||
deLang = await tryDetectLang(
|
deLang = await tryDetectLang(
|
||||||
|
|||||||
@@ -113,8 +113,8 @@ function RuleFields({ rule, rules, setShow, setKeyword }) {
|
|||||||
transTag = DEFAULT_TRANS_TAG,
|
transTag = DEFAULT_TRANS_TAG,
|
||||||
transTitle = "false",
|
transTitle = "false",
|
||||||
transSelected = "true",
|
transSelected = "true",
|
||||||
detectRemote = "true",
|
// detectRemote = "true",
|
||||||
skipLangs = [],
|
// skipLangs = [],
|
||||||
// fixerSelector = "",
|
// fixerSelector = "",
|
||||||
// fixerFunc = "-",
|
// fixerFunc = "-",
|
||||||
transStartHook = "",
|
transStartHook = "",
|
||||||
@@ -478,23 +478,6 @@ function RuleFields({ rule, rules, setShow, setKeyword }) {
|
|||||||
))}
|
))}
|
||||||
</TextField>
|
</TextField>
|
||||||
</Grid> */}
|
</Grid> */}
|
||||||
|
|
||||||
<Grid item xs={12} sm={12} md={6} lg={3}>
|
|
||||||
<TextField
|
|
||||||
select
|
|
||||||
size="small"
|
|
||||||
fullWidth
|
|
||||||
name="detectRemote"
|
|
||||||
value={detectRemote}
|
|
||||||
label={i18n("detect_lang_remote")}
|
|
||||||
disabled={disabled}
|
|
||||||
onChange={handleChange}
|
|
||||||
>
|
|
||||||
{GlobalItem}
|
|
||||||
<MenuItem value={"false"}>{i18n("disable")}</MenuItem>
|
|
||||||
<MenuItem value={"true"}>{i18n("enable")}</MenuItem>
|
|
||||||
</TextField>
|
|
||||||
</Grid>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
@@ -549,26 +532,6 @@ function RuleFields({ rule, rules, setShow, setKeyword }) {
|
|||||||
|
|
||||||
{showMore && (
|
{showMore && (
|
||||||
<>
|
<>
|
||||||
<TextField
|
|
||||||
select
|
|
||||||
size="small"
|
|
||||||
label={i18n("skip_langs")}
|
|
||||||
helperText={i18n("skip_langs_helper")}
|
|
||||||
name="skipLangs"
|
|
||||||
value={skipLangs}
|
|
||||||
disabled={disabled}
|
|
||||||
onChange={handleChange}
|
|
||||||
SelectProps={{
|
|
||||||
multiple: true,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{OPT_LANGS_TO.map(([langKey, langName]) => (
|
|
||||||
<MenuItem key={langKey} value={langKey}>
|
|
||||||
{langName}
|
|
||||||
</MenuItem>
|
|
||||||
))}
|
|
||||||
</TextField>
|
|
||||||
|
|
||||||
<TextField
|
<TextField
|
||||||
size="small"
|
size="small"
|
||||||
label={i18n("terms")}
|
label={i18n("terms")}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import {
|
|||||||
MSG_CONTEXT_MENUS,
|
MSG_CONTEXT_MENUS,
|
||||||
MSG_UPDATE_CSP,
|
MSG_UPDATE_CSP,
|
||||||
DEFAULT_HTTP_TIMEOUT,
|
DEFAULT_HTTP_TIMEOUT,
|
||||||
|
OPT_LANGS_TO,
|
||||||
} from "../../config";
|
} from "../../config";
|
||||||
import { useShortcut } from "../../hooks/Shortcut";
|
import { useShortcut } from "../../hooks/Shortcut";
|
||||||
import ShortcutInput from "./ShortcutInput";
|
import ShortcutInput from "./ShortcutInput";
|
||||||
@@ -119,6 +120,8 @@ export default function Settings() {
|
|||||||
transInterval = 100,
|
transInterval = 100,
|
||||||
langDetector = OPT_TRANS_MICROSOFT,
|
langDetector = OPT_TRANS_MICROSOFT,
|
||||||
preInit = true,
|
preInit = true,
|
||||||
|
skipLangs = [],
|
||||||
|
detectRemote = true,
|
||||||
} = setting;
|
} = setting;
|
||||||
const { isHide = false, fabClickAction = 0 } = fab || {};
|
const { isHide = false, fabClickAction = 0 } = fab || {};
|
||||||
|
|
||||||
@@ -297,6 +300,20 @@ export default function Settings() {
|
|||||||
<MenuItem value={2}>{i18n("secondary_context_menus")}</MenuItem>
|
<MenuItem value={2}>{i18n("secondary_context_menus")}</MenuItem>
|
||||||
</TextField>
|
</TextField>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
<Grid item xs={12} sm={12} md={6} lg={3}>
|
||||||
|
<TextField
|
||||||
|
select
|
||||||
|
size="small"
|
||||||
|
fullWidth
|
||||||
|
name="detectRemote"
|
||||||
|
value={detectRemote}
|
||||||
|
label={i18n("detect_lang_remote")}
|
||||||
|
onChange={handleChange}
|
||||||
|
>
|
||||||
|
<MenuItem value={true}>{i18n("enable")}</MenuItem>
|
||||||
|
<MenuItem value={false}>{i18n("disable")}</MenuItem>
|
||||||
|
</TextField>
|
||||||
|
</Grid>
|
||||||
<Grid item xs={12} sm={12} md={6} lg={3}>
|
<Grid item xs={12} sm={12} md={6} lg={3}>
|
||||||
<TextField
|
<TextField
|
||||||
select
|
select
|
||||||
@@ -304,7 +321,7 @@ export default function Settings() {
|
|||||||
size="small"
|
size="small"
|
||||||
name="langDetector"
|
name="langDetector"
|
||||||
value={langDetector}
|
value={langDetector}
|
||||||
label={i18n("detect_lang_remote")}
|
label={i18n("detect_lang_serve")}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
>
|
>
|
||||||
{OPT_LANGDETECTOR_ALL.map((item) => (
|
{OPT_LANGDETECTOR_ALL.map((item) => (
|
||||||
@@ -317,6 +334,25 @@ export default function Settings() {
|
|||||||
</Grid>
|
</Grid>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
|
<TextField
|
||||||
|
select
|
||||||
|
size="small"
|
||||||
|
label={i18n("skip_langs")}
|
||||||
|
helperText={i18n("skip_langs_helper")}
|
||||||
|
name="skipLangs"
|
||||||
|
value={skipLangs}
|
||||||
|
onChange={handleChange}
|
||||||
|
SelectProps={{
|
||||||
|
multiple: true,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{OPT_LANGS_TO.map(([langKey, langName]) => (
|
||||||
|
<MenuItem key={langKey} value={langKey}>
|
||||||
|
{langName}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</TextField>
|
||||||
|
|
||||||
{isExt ? (
|
{isExt ? (
|
||||||
<>
|
<>
|
||||||
<TextField
|
<TextField
|
||||||
|
|||||||
Reference in New Issue
Block a user