Skip to content

Commit

Permalink
add yandex translate
Browse files Browse the repository at this point in the history
  • Loading branch information
troyeguo committed Dec 31, 2023
1 parent 8ed91ea commit 75f334e
Show file tree
Hide file tree
Showing 15 changed files with 329 additions and 73 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
"howler": "^2.2.3",
"iconv-lite": "^0.6.3",
"onedrive-api": "^1.1.1",
"qs": "^6.11.2",
"react-hot-toast": "^2.1.1",
"request": "^2.88.2",
"uuid": "^9.0.1",
"webdav": "^3.6.2",
"webdav-fs": "^3.0.0",
"wink-lemmatizer": "^3.0.4",
Expand Down
Binary file modified src/assets/styles/fonts/icomoon.eot
Binary file not shown.
1 change: 1 addition & 0 deletions src/assets/styles/fonts/icomoon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/styles/fonts/icomoon.ttf
Binary file not shown.
Binary file modified src/assets/styles/fonts/icomoon.woff
Binary file not shown.
13 changes: 8 additions & 5 deletions src/assets/styles/style.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@font-face {
font-family: 'icomoon';
src: url('fonts/icomoon.eot?5jeq75');
src: url('fonts/icomoon.eot?5jeq75#iefix') format('embedded-opentype'),
url('fonts/icomoon.ttf?5jeq75') format('truetype'),
url('fonts/icomoon.woff?5jeq75') format('woff'),
url('fonts/icomoon.svg?5jeq75#icomoon') format('svg');
src: url('fonts/icomoon.eot?x2g1mi');
src: url('fonts/icomoon.eot?x2g1mi#iefix') format('embedded-opentype'),
url('fonts/icomoon.ttf?x2g1mi') format('truetype'),
url('fonts/icomoon.woff?x2g1mi') format('woff'),
url('fonts/icomoon.svg?x2g1mi#icomoon') format('svg');
font-weight: normal;
font-style: normal;
font-display: block;
Expand All @@ -25,6 +25,9 @@
-moz-osx-font-smoothing: grayscale;
}

.icon-yandex:before {
content: "\e953";
}
.icon-deepl:before {
content: "\e952";
}
Expand Down
29 changes: 1 addition & 28 deletions src/components/popups/popupDict/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Parser from "html-react-parser";
import * as DOMPurify from "dompurify";
import axios from "axios";
import { getBingDict } from "../../../utils/serviceUtils/bingDictUtil";
import { openExternalUrl } from "../../../utils/serviceUtils/urlUtil";
import RecordLocation from "../../../utils/readUtils/recordLocation";
import DictHistory from "../../../model/DictHistory";
import { Trans } from "react-i18next";
Expand Down Expand Up @@ -219,33 +218,7 @@ class PopupDict extends React.Component<PopupDictProps, PopupDictState> {
DOMPurify.sanitize(this.state.dictText + "<address></address>") ||
" ",
{
replace: (domNode) => {
if (this.state.dictService === "Yandex.Dictionary") {
if (domNode.name === "address") {
delete domNode.attribs.onclick;
return (
<p
onClick={() => {
openExternalUrl(
this.state.dictService
? dictList.filter(
(item) =>
item.name === this.state.dictService
)[0].url
: dictList[0].url
);
}}
className="dict-url"
>
{"Powered by " +
(this.state.dictService
? this.state.dictService
: "Free Dictionary API")}
</p>
);
}
}
},
replace: (domNode) => {},
}
)}
</div>
Expand Down
45 changes: 41 additions & 4 deletions src/components/popups/popupTrans/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import {
googleTransList,
edgeTransList,
deeplTransList,
yandexTransList,
} from "../../../constants/translationList";
import StorageUtil from "../../../utils/serviceUtils/storageUtil";
import { bingTranlate } from "../../../utils/serviceUtils/bingTransUtil";
import { deeplTranlate } from "../../../utils/serviceUtils/deeplTransUtil";
import { bingTranslate } from "../../../utils/serviceUtils/bingTransUtil";
import { deeplTranslate } from "../../../utils/serviceUtils/deeplTransUtil";
import { yandexTranslate } from "../../../utils/serviceUtils/yandexTransUtil";
class PopupTrans extends React.Component<PopupTransProps, PopupTransState> {
constructor(props: PopupTransProps) {
super(props);
Expand All @@ -27,7 +29,21 @@ class PopupTrans extends React.Component<PopupTransProps, PopupTransState> {
}
handleTrans = (text: string) => {
if (this.state.transService === "Bing") {
bingTranlate(
bingTranslate(
text,
StorageUtil.getReaderConfig("transSource") || "",
StorageUtil.getReaderConfig("transTarget") || "en"
)
.then((res) => {
this.setState({
translatedText: res,
});
})
.catch((err) => {
console.log(err);
});
} else if (this.state.transService === "Yandex") {
yandexTranslate(
text,
StorageUtil.getReaderConfig("transSource") || "",
StorageUtil.getReaderConfig("transTarget") || "en"
Expand All @@ -41,7 +57,7 @@ class PopupTrans extends React.Component<PopupTransProps, PopupTransState> {
console.log(err);
});
} else if (this.state.transService === "Deepl") {
deeplTranlate(
deeplTranslate(
text,
StorageUtil.getReaderConfig("transSource") || "auto",
StorageUtil.getReaderConfig("transTarget") || "EN"
Expand Down Expand Up @@ -128,6 +144,19 @@ class PopupTrans extends React.Component<PopupTransProps, PopupTransState> {
<span className="icon-deepl trans-deepl-icon"></span>
Deepl
</div>
<div
className={
this.state.transService === "Yandex"
? "trans-service-selector"
: "trans-service-selector-inactive"
}
onClick={() => {
this.handleChangeService("Yandex");
}}
>
<span className="icon-yandex trans-yandex-icon"></span>
Yandex
</div>
</div>
<div className="trans-lang-selector-container">
<div className="original-lang-box">
Expand All @@ -146,6 +175,8 @@ class PopupTrans extends React.Component<PopupTransProps, PopupTransState> {
? Object.keys(googleTransList)
: this.state.transService === "Deepl"
? Object.keys(deeplTransList)
: this.state.transService === "Yandex"
? Object.keys(yandexTransList)
: Object.keys(edgeTransList)
).map((item, index) => {
return (
Expand All @@ -164,6 +195,8 @@ class PopupTrans extends React.Component<PopupTransProps, PopupTransState> {
? Object.values(googleTransList)
: this.state.transService === "Deepl"
? Object.values(deeplTransList)
: this.state.transService === "Yandex"
? Object.values(yandexTransList)
: Object.values(edgeTransList))[index]
}
</option>
Expand All @@ -187,6 +220,8 @@ class PopupTrans extends React.Component<PopupTransProps, PopupTransState> {
? Object.keys(googleTransList)
: this.state.transService === "Deepl"
? Object.keys(deeplTransList)
: this.state.transService === "Yandex"
? Object.keys(yandexTransList)
: Object.keys(edgeTransList)
).map((item, index) => {
return (
Expand All @@ -205,6 +240,8 @@ class PopupTrans extends React.Component<PopupTransProps, PopupTransState> {
? Object.values(googleTransList)
: this.state.transService === "Deepl"
? Object.values(deeplTransList)
: this.state.transService === "Yandex"
? Object.values(yandexTransList)
: Object.values(edgeTransList))[index]
}
</option>
Expand Down
8 changes: 6 additions & 2 deletions src/components/popups/popupTrans/popupTrans.css
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@
font-size: 14px;
}
.trans-deepl-icon {
font-size: 14px;
font-size: 15px;
}
.trans-yandex-icon {
font-size: 13px;
font-weight: bold;
}
.trans-service-selector-inactive {
border: 1px solid rgba(0, 0, 0, 0.05);
Expand All @@ -119,7 +123,7 @@
.trans-service-selector-container {
position: absolute;
top: 20px;
width: 270px;
width: 360px;
display: flex;
justify-content: space-between;
}
Expand Down
6 changes: 5 additions & 1 deletion src/constants/dictList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ export const dictList = [
url: "https://dictionaryapi.dev/",
},
{
name: "Google Dictionary",
name: "Google Dict",
url: "https://www.google.com",
},
{
name: "必应词典",
url: "https://www.bing.com/dict",
},
{
name: "Cambridge Dict",
url: "https://dictionary.cambridge.org",
},
];
Loading

0 comments on commit 75f334e

Please sign in to comment.