feat: lang detector can be selected
This commit is contained in:
@@ -101,7 +101,14 @@ function Header({
|
||||
);
|
||||
}
|
||||
|
||||
function TranForm({ text, setText, tranboxSetting, transApis, simpleStyle }) {
|
||||
function TranForm({
|
||||
text,
|
||||
setText,
|
||||
tranboxSetting,
|
||||
transApis,
|
||||
simpleStyle,
|
||||
langDetector,
|
||||
}) {
|
||||
const i18n = useI18n();
|
||||
|
||||
const [editMode, setEditMode] = useState(false);
|
||||
@@ -242,6 +249,7 @@ function TranForm({ text, setText, tranboxSetting, transApis, simpleStyle }) {
|
||||
toLang2={tranboxSetting.toLang2}
|
||||
transApis={transApis}
|
||||
simpleStyle={simpleStyle}
|
||||
langDetector={langDetector}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -268,6 +276,7 @@ export default function TranBox({
|
||||
followSelection,
|
||||
setFollowSelection,
|
||||
extStyles,
|
||||
langDetector,
|
||||
}) {
|
||||
const [mouseHover, setMouseHover] = useState(false);
|
||||
return (
|
||||
@@ -300,6 +309,7 @@ export default function TranBox({
|
||||
tranboxSetting={tranboxSetting}
|
||||
transApis={transApis}
|
||||
simpleStyle={simpleStyle}
|
||||
langDetector={langDetector}
|
||||
/>
|
||||
</DraggableResizable>
|
||||
</ThemeProvider>
|
||||
|
||||
@@ -5,10 +5,11 @@ import Stack from "@mui/material/Stack";
|
||||
import { useI18n } from "../../hooks/I18n";
|
||||
import { DEFAULT_TRANS_APIS } from "../../config";
|
||||
import { useEffect, useState } from "react";
|
||||
import { apiTranslate, apiBaiduLangdetect } from "../../apis";
|
||||
import { apiTranslate } from "../../apis";
|
||||
import CopyBtn from "./CopyBtn";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import Alert from "@mui/material/Alert";
|
||||
import { tryDetectLang } from "../../libs";
|
||||
|
||||
export default function TranCont({
|
||||
text,
|
||||
@@ -18,6 +19,7 @@ export default function TranCont({
|
||||
toLang2 = "en",
|
||||
transApis,
|
||||
simpleStyle,
|
||||
langDetector,
|
||||
}) {
|
||||
const i18n = useI18n();
|
||||
const [trText, setTrText] = useState("");
|
||||
@@ -33,7 +35,7 @@ export default function TranCont({
|
||||
|
||||
let to = toLang;
|
||||
if (toLang !== toLang2 && toLang2 !== "none") {
|
||||
const detectLang = await apiBaiduLangdetect(text);
|
||||
const detectLang = await tryDetectLang(text, true, langDetector);
|
||||
if (detectLang === toLang) {
|
||||
to = toLang2;
|
||||
}
|
||||
@@ -55,7 +57,7 @@ export default function TranCont({
|
||||
setLoading(false);
|
||||
}
|
||||
})();
|
||||
}, [text, translator, fromLang, toLang, toLang2, transApis]);
|
||||
}, [text, translator, fromLang, toLang, toLang2, transApis, langDetector]);
|
||||
|
||||
if (simpleStyle) {
|
||||
return (
|
||||
|
||||
@@ -20,6 +20,7 @@ export default function Slection({
|
||||
tranboxSetting,
|
||||
transApis,
|
||||
uiLang,
|
||||
langDetector,
|
||||
}) {
|
||||
const {
|
||||
hideTranBtn = false,
|
||||
@@ -234,6 +235,7 @@ export default function Slection({
|
||||
followSelection={followSelection}
|
||||
setFollowSelection={setFollowSelection}
|
||||
extStyles={extStyles}
|
||||
langDetector={langDetector}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user