feat: Support for multiple translation services in tranbox

This commit is contained in:
Gabe
2025-10-02 11:33:33 +08:00
parent 039566ded5
commit 389f0b6f82
9 changed files with 41 additions and 36 deletions

View File

@@ -13,7 +13,6 @@ import {
UI_LANGS,
TRANS_NEWLINE_LENGTH,
CACHE_NAME,
OPT_TRANS_MICROSOFT,
OPT_LANGDETECTOR_ALL,
OPT_SHORTCUT_TRANSLATE,
OPT_SHORTCUT_STYLE,
@@ -118,10 +117,10 @@ export default function Settings() {
blacklist = DEFAULT_BLACKLIST.join(",\n"),
csplist = DEFAULT_CSPLIST.join(",\n"),
transInterval = 100,
langDetector = OPT_TRANS_MICROSOFT,
langDetector = "-",
preInit = true,
skipLangs = [],
detectRemote = true,
// detectRemote = true,
transAllnow = false,
} = setting;
const { isHide = false, fabClickAction = 0 } = fab || {};
@@ -315,7 +314,7 @@ export default function Settings() {
<MenuItem value={true}>{i18n("mk_pageopen")}</MenuItem>
</TextField>
</Grid>
<Grid item xs={12} sm={12} md={6} lg={3}>
{/* <Grid item xs={12} sm={12} md={6} lg={3}>
<TextField
select
size="small"
@@ -328,7 +327,7 @@ export default function Settings() {
<MenuItem value={true}>{i18n("enable")}</MenuItem>
<MenuItem value={false}>{i18n("disable")}</MenuItem>
</TextField>
</Grid>
</Grid> */}
<Grid item xs={12} sm={12} md={6} lg={3}>
<TextField
select
@@ -336,9 +335,10 @@ export default function Settings() {
size="small"
name="langDetector"
value={langDetector}
label={i18n("detect_lang_service")}
label={i18n("detect_lang_remote")}
onChange={handleChange}
>
<MenuItem value={"-"}>{i18n("disable")}</MenuItem>
{OPT_LANGDETECTOR_ALL.map((item) => (
<MenuItem value={item} key={item}>
{item}

View File

@@ -51,7 +51,7 @@ export default function Tranbox() {
const {
transOpen,
apiSlug,
apiSlugs,
fromLang,
toLang,
toLang2 = "en",
@@ -88,15 +88,18 @@ export default function Tranbox() {
<Box>
<Grid container spacing={2} columns={12}>
<Grid item xs={12} sm={12} md={6} lg={3}>
<Grid item xs={12} sm={12} md={12} lg={6}>
<TextField
select
fullWidth
size="small"
name="apiSlug"
value={apiSlug}
label={i18n("translate_service")}
name="apiSlugs"
value={apiSlugs}
label={i18n("translate_service_multiple")}
onChange={handleChange}
SelectProps={{
multiple: true,
}}
>
{enabledApis.map((api) => (
<MenuItem key={api.apiSlug} value={api.apiSlug}>

View File

@@ -287,7 +287,7 @@ function TranForm({
/>
)}
{enDict !== "-" && (
{enDict !== "-" && isValidWord(text) && (
<>
<DictCont text={text} />
<SugCont text={text} />

View File

@@ -18,7 +18,7 @@ export default function TranCont({
toLang,
toLang2 = "en",
transApis,
simpleStyle,
simpleStyle = false,
langDetector,
}) {
const i18n = useI18n();
@@ -27,6 +27,10 @@ export default function TranCont({
const [error, setError] = useState("");
useEffect(() => {
if (!text?.trim()) {
return;
}
(async () => {
try {
setLoading(true);