feat: disable languages
This commit is contained in:
@@ -687,4 +687,12 @@ export const I18N = {
|
|||||||
zh: `禁用翻译名单`,
|
zh: `禁用翻译名单`,
|
||||||
en: `Translate Blacklist`,
|
en: `Translate Blacklist`,
|
||||||
},
|
},
|
||||||
|
disable_langs: {
|
||||||
|
zh: `不翻译的语言`,
|
||||||
|
en: `Disable Languages`,
|
||||||
|
},
|
||||||
|
disable_langs_helper: {
|
||||||
|
zh: `此功能依赖准确的语言检测,建议启用远程语言检测。`,
|
||||||
|
en: `This feature relies on accurate language detection. It is recommended to enable remote language detection.`,
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -441,6 +441,7 @@ export const DEFAULT_SETTING = {
|
|||||||
tranboxSetting: DEFAULT_TRANBOX_SETTING, // 划词翻译设置
|
tranboxSetting: DEFAULT_TRANBOX_SETTING, // 划词翻译设置
|
||||||
touchTranslate: 2, // 触屏翻译
|
touchTranslate: 2, // 触屏翻译
|
||||||
blacklist: DEFAULT_BLACKLIST.join(",\n"), // 禁用翻译名单
|
blacklist: DEFAULT_BLACKLIST.join(",\n"), // 禁用翻译名单
|
||||||
|
disableLangs: [], // 不翻译的语言
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DEFAULT_RULES = [GLOBLA_RULE];
|
export const DEFAULT_RULES = [GLOBLA_RULE];
|
||||||
|
|||||||
@@ -24,7 +24,11 @@ export function useTranslate(q, rule, setting) {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
const deLang = await tryDetectLang(q, setting.detectRemote);
|
const deLang = await tryDetectLang(q, setting.detectRemote);
|
||||||
if (deLang && toLang.includes(deLang)) {
|
const disableLangs = setting.disableLangs || [];
|
||||||
|
if (
|
||||||
|
deLang &&
|
||||||
|
(toLang.includes(deLang) || disableLangs.includes(deLang))
|
||||||
|
) {
|
||||||
setSamelang(true);
|
setSamelang(true);
|
||||||
} else {
|
} else {
|
||||||
const [trText, isSame] = await apiTranslate({
|
const [trText, isSame] = await apiTranslate({
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import {
|
|||||||
OPT_SHORTCUT_STYLE,
|
OPT_SHORTCUT_STYLE,
|
||||||
OPT_SHORTCUT_POPUP,
|
OPT_SHORTCUT_POPUP,
|
||||||
OPT_SHORTCUT_SETTING,
|
OPT_SHORTCUT_SETTING,
|
||||||
|
OPT_LANGS_TO,
|
||||||
DEFAULT_BLACKLIST,
|
DEFAULT_BLACKLIST,
|
||||||
} from "../../config";
|
} from "../../config";
|
||||||
import { useShortcut } from "../../hooks/Shortcut";
|
import { useShortcut } from "../../hooks/Shortcut";
|
||||||
@@ -43,6 +44,7 @@ export default function Settings() {
|
|||||||
const { fab, updateFab } = useFab();
|
const { fab, updateFab } = useFab();
|
||||||
|
|
||||||
const handleChange = (e) => {
|
const handleChange = (e) => {
|
||||||
|
console.log("e", e);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
let { name, value } = e.target;
|
let { name, value } = e.target;
|
||||||
switch (name) {
|
switch (name) {
|
||||||
@@ -92,6 +94,7 @@ export default function Settings() {
|
|||||||
detectRemote = false,
|
detectRemote = false,
|
||||||
touchTranslate = 2,
|
touchTranslate = 2,
|
||||||
blacklist = DEFAULT_BLACKLIST.join(",\n"),
|
blacklist = DEFAULT_BLACKLIST.join(",\n"),
|
||||||
|
disableLangs = [],
|
||||||
} = setting;
|
} = setting;
|
||||||
const { isHide = false } = fab || {};
|
const { isHide = false } = fab || {};
|
||||||
|
|
||||||
@@ -220,6 +223,24 @@ export default function Settings() {
|
|||||||
<FormHelperText>{i18n("detect_lang_remote_help")}</FormHelperText>
|
<FormHelperText>{i18n("detect_lang_remote_help")}</FormHelperText>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|
||||||
|
<FormControl>
|
||||||
|
<InputLabel>{i18n("disable_langs")}</InputLabel>
|
||||||
|
<Select
|
||||||
|
multiple
|
||||||
|
name="disableLangs"
|
||||||
|
value={disableLangs}
|
||||||
|
label={i18n("disable_langs")}
|
||||||
|
onChange={handleChange}
|
||||||
|
>
|
||||||
|
{OPT_LANGS_TO.map(([langKey, langName]) => (
|
||||||
|
<MenuItem key={langKey} value={langKey}>
|
||||||
|
{langName}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
<FormHelperText>{i18n("disable_langs_helper")}</FormHelperText>
|
||||||
|
</FormControl>
|
||||||
|
|
||||||
{isExt ? (
|
{isExt ? (
|
||||||
<FormControl size="small">
|
<FormControl size="small">
|
||||||
<InputLabel>{i18n("if_clear_cache")}</InputLabel>
|
<InputLabel>{i18n("if_clear_cache")}</InputLabel>
|
||||||
|
|||||||
Reference in New Issue
Block a user