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.`,
|
||||
zh_TW: `啟用後可提升偵測準確度,但會降低翻譯速度,請視需要開啟。`,
|
||||
},
|
||||
detect_lang_service: {
|
||||
zh: `语言检测服务`,
|
||||
en: `Language detect service`,
|
||||
zh_TW: `語言檢測服務`,
|
||||
},
|
||||
disable: {
|
||||
zh: `禁用`,
|
||||
en: `Disable`,
|
||||
|
||||
@@ -96,8 +96,8 @@ export const DEFAULT_RULE = {
|
||||
transTag: GLOBAL_KEY, // 译文元素标签
|
||||
transTitle: GLOBAL_KEY, // 是否同时翻译页面标题
|
||||
transSelected: GLOBAL_KEY, // 是否启用划词翻译
|
||||
detectRemote: GLOBAL_KEY, // 是否使用远程语言检测
|
||||
skipLangs: [], // 不翻译的语言
|
||||
// detectRemote: GLOBAL_KEY, // 是否使用远程语言检测 (移回setting)
|
||||
// skipLangs: [], // 不翻译的语言 (移回setting)
|
||||
// fixerSelector: "", // 修复函数选择器 (暂时作废)
|
||||
// fixerFunc: GLOBAL_KEY, // 修复函数 (暂时作废)
|
||||
transStartHook: "", // 钩子函数
|
||||
@@ -132,8 +132,8 @@ export const GLOBLA_RULE = {
|
||||
transTag: DEFAULT_TRANS_TAG, // 译文元素标签
|
||||
transTitle: "false", // 是否同时翻译页面标题
|
||||
transSelected: "true", // 是否启用划词翻译
|
||||
detectRemote: "true", // 是否使用远程语言检测
|
||||
skipLangs: [], // 不翻译的语言
|
||||
// detectRemote: "true", // 是否使用远程语言检测 (移回setting)
|
||||
// skipLangs: [], // 不翻译的语言 (移回setting)
|
||||
// fixerSelector: "", // 修复函数选择器 (暂时作废)
|
||||
// fixerFunc: "-", // 修复函数 (暂时作废)
|
||||
transStartHook: "", // 钩子函数
|
||||
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
OPT_TRANS_MICROSOFT,
|
||||
DEFAULT_API_LIST,
|
||||
} from "./api";
|
||||
import { DEFAULT_OW_RULE } from "./rules";
|
||||
|
||||
// 默认快捷键
|
||||
export const OPT_SHORTCUT_TRANSLATE = "toggleTranslate";
|
||||
@@ -128,7 +127,7 @@ export const DEFAULT_SETTING = {
|
||||
injectRules: true, // 是否注入订阅规则
|
||||
fabClickAction: 0, // 悬浮按钮点击行为
|
||||
// injectWebfix: true, // 是否注入修复补丁(作废)
|
||||
// detectRemote: false, // 是否使用远程语言检测(移至rule,作废)
|
||||
detectRemote: false, // 是否使用远程语言检测 (从rule移回)
|
||||
// contextMenus: true, // 是否添加右键菜单(作废)
|
||||
contextMenuType: 1, // 右键菜单类型(0不显示,1简单菜单,2多级菜单)
|
||||
// transTag: DEFAULT_TRANS_TAG, // 译文元素标签(移至rule,作废)
|
||||
@@ -145,6 +144,7 @@ export const DEFAULT_SETTING = {
|
||||
blacklist: DEFAULT_BLACKLIST.join(",\n"), // 禁用翻译名单
|
||||
csplist: DEFAULT_CSPLIST.join(",\n"), // 禁用CSP名单
|
||||
// disableLangs: [], // 不翻译的语言(移至rule,作废)
|
||||
skipLangs: [], // 不翻译的语言(从rule移回)
|
||||
transInterval: 100, // 翻译等待时间
|
||||
langDetector: OPT_TRANS_MICROSOFT, // 远程语言识别服务
|
||||
mouseHoverSetting: DEFAULT_MOUSE_HOVER_SETTING, // 鼠标悬停翻译
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 : "",
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -113,8 +113,8 @@ function RuleFields({ rule, rules, setShow, setKeyword }) {
|
||||
transTag = DEFAULT_TRANS_TAG,
|
||||
transTitle = "false",
|
||||
transSelected = "true",
|
||||
detectRemote = "true",
|
||||
skipLangs = [],
|
||||
// detectRemote = "true",
|
||||
// skipLangs = [],
|
||||
// fixerSelector = "",
|
||||
// fixerFunc = "-",
|
||||
transStartHook = "",
|
||||
@@ -478,23 +478,6 @@ function RuleFields({ rule, rules, setShow, setKeyword }) {
|
||||
))}
|
||||
</TextField>
|
||||
</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>
|
||||
</Box>
|
||||
|
||||
@@ -549,26 +532,6 @@ function RuleFields({ rule, rules, setShow, setKeyword }) {
|
||||
|
||||
{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
|
||||
size="small"
|
||||
label={i18n("terms")}
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
MSG_CONTEXT_MENUS,
|
||||
MSG_UPDATE_CSP,
|
||||
DEFAULT_HTTP_TIMEOUT,
|
||||
OPT_LANGS_TO,
|
||||
} from "../../config";
|
||||
import { useShortcut } from "../../hooks/Shortcut";
|
||||
import ShortcutInput from "./ShortcutInput";
|
||||
@@ -119,6 +120,8 @@ export default function Settings() {
|
||||
transInterval = 100,
|
||||
langDetector = OPT_TRANS_MICROSOFT,
|
||||
preInit = true,
|
||||
skipLangs = [],
|
||||
detectRemote = true,
|
||||
} = setting;
|
||||
const { isHide = false, fabClickAction = 0 } = fab || {};
|
||||
|
||||
@@ -297,6 +300,20 @@ export default function Settings() {
|
||||
<MenuItem value={2}>{i18n("secondary_context_menus")}</MenuItem>
|
||||
</TextField>
|
||||
</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}>
|
||||
<TextField
|
||||
select
|
||||
@@ -304,7 +321,7 @@ export default function Settings() {
|
||||
size="small"
|
||||
name="langDetector"
|
||||
value={langDetector}
|
||||
label={i18n("detect_lang_remote")}
|
||||
label={i18n("detect_lang_serve")}
|
||||
onChange={handleChange}
|
||||
>
|
||||
{OPT_LANGDETECTOR_ALL.map((item) => (
|
||||
@@ -317,6 +334,25 @@ export default function Settings() {
|
||||
</Grid>
|
||||
</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 ? (
|
||||
<>
|
||||
<TextField
|
||||
|
||||
Reference in New Issue
Block a user