Skip to content

Commit

Permalink
fix: web page translating might ignore some elements
Browse files Browse the repository at this point in the history
  • Loading branch information
chunibyocola committed Aug 9, 2021
1 parent 6ffb7b4 commit 9f8cd55
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/public/web-page-translate/google/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export const translate = async (searchParams: URLSearchParams, totalQText: strin

const toResult = (rawResult: string) => {
let result: string[] = [];
let preprocessText = rawResult.replace(/<i>.*?<\/i>/g, '').replace(/<[\/]?b>/g, '');
let matchArray = preprocessText.match(/(?<=<a i=)[0-9]+>.*?(?=<\/a>)/g);
let preprocessText = rawResult.replace(/<i>[\s\S]*?<\/i>/g, '').replace(/<[\/]?b>/g, '');
let matchArray = preprocessText.match(/(?<=<a i=)[0-9]+>[\s\S]*?(?=<\/a>)/g);
if (matchArray) {
matchArray.map(v => {
const [index, rawResult] = v.split('>');
Expand Down
6 changes: 3 additions & 3 deletions src/public/web-page-translate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ let wayOfFontsDisplaying: number = 1;
let waitingList: PageTranslateItemEnity[] = [];
let updatedList: PageTranslateItemEnity[] = [];

const preIgnoreTagRegExp = /CANVAS|IFRAME|BR|HR|SVG|IMG|SCRIPT|LINK|STYLE|INPUT|TEXTAREA|CODE|#comment/i;
const ignoreTagRegExp = /CANVAS|IFRAME|BR|HR|SVG|IMG|SCRIPT|LINK|STYLE|INPUT|TEXTAREA/i;
const skipTagRegExp = /CODE|#comment/i;
const preIgnoreTagRegExp = /^(CANVAS|IFRAME|BR|HR|SVG|IMG|SCRIPT|LINK|STYLE|INPUT|TEXTAREA|CODE|#comment)$/i;
const ignoreTagRegExp = /^(CANVAS|IFRAME|BR|HR|SVG|IMG|SCRIPT|LINK|STYLE|INPUT|TEXTAREA)$/i;
const skipTagRegExp = /^(CODE|#comment)$/i;
let minViewPort = 0;
let maxViewPort = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/public/web-page-translate/microsoft/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const fetchFromMicrosoft = async (requestArray: { Text: string }[], targetLangua

const toResult = (rawResult: string) => {
let result: string[] = [];
let matchArray = rawResult.match(/(?<=<b)[0-9]+>.*?(?=<\/b[0-9]+>)/g);
let matchArray = rawResult.match(/(?<=<b)[0-9]+>[\s\S]*?(?=<\/b[0-9]+>)/g);
if (matchArray) {
matchArray.map(v => {
const [index, rawResult] = v.split('>');
Expand Down

0 comments on commit 9f8cd55

Please sign in to comment.