Skip to content

Commit

Permalink
fix: 修复翻译结果有多余换行的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Pylogmon committed May 25, 2023
1 parent 7adee1c commit f29a9d3
Show file tree
Hide file tree
Showing 15 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/interfaces/alibaba.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export async function translate(text, from, to, setText, id) {
}
}
if (translateID.includes(id)) {
setText(result['Data']['Translated']);
setText(result['Data']['Translated'].trim());
}
} else {
throw JSON.stringify(result);
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/baidu.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export async function translate(text, from, to, setText, id) {
target = target + trans_result[i]['dst'] + '\n';
}
if (translateID.includes(id)) {
setText(target);
setText(target.trim());
}
} else {
throw JSON.stringify(result);
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/bing.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export async function translate(text, from, to, setText, id) {
}

if (translateID.includes(id)) {
setText(result[0].translations[0].text);
setText(result[0].translations[0].text.trim());
}
} else {
throw JSON.stringify(result);
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/bing_dict.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export async function translate(text, from, to, setText, id) {
throw '查词失败';
} else {
if (translateID.includes(id)) {
setText(content);
setText(content.trim());
}
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/caiyun.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export async function translate(text, from, to, setText, id) {
setText(target[0]);
}
} else {
throw JSON.stringify(result);
throw JSON.stringify(result.trim());
}
} else {
throw `Http请求错误\nHttp Status: ${res.status}\n${JSON.stringify(res.data)}`;
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/deepl.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export async function translate(text, from, to, setText, id) {
}
}
if (translateID.includes(id)) {
setText(result.result.texts[0].text);
setText(result.result.texts[0].text.trim());
}
} else {
throw JSON.stringify(result);
Expand Down Expand Up @@ -160,7 +160,7 @@ async function translate_by_key(text, from, to, setText, id, key) {
}
}
if (translateID.includes(id)) {
setText(result.translations[0].text);
setText(result.translations[0].text.trim());
}
} else {
throw JSON.stringify(result);
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/google.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export async function translate(text, from, to, setText, id) {
target += '\n';
}
if (translateID.includes(id)) {
setText(target);
setText(target.trim());
}
} else {
// 翻译模式
Expand All @@ -97,7 +97,7 @@ export async function translate(text, from, to, setText, id) {
}
}
if (translateID.includes(id)) {
setText(target);
setText(target.trim());
}
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/lingva.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export async function translate(text, from, to, setText, id) {
}
}
if (translateID.includes(id)) {
setText(result.translation.replaceAll('@@', '/'));
setText(result.translation.replaceAll('@@', '/').trim());
}
} else {
throw JSON.stringify(result);
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/openai.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export async function translate(text, from, to, setText, id) {
const { done, value } = await reader.read();
if (done) {
if (translateID.includes(id)) {
setText(target);
setText(target.trim());
}
break;
}
Expand Down Expand Up @@ -166,7 +166,7 @@ export async function translate(text, from, to, setText, id) {
target = target.slice(0, -1);
}
if (translateID.includes(id)) {
setText(target);
setText(target.trim());
}
} else {
throw JSON.stringify(choices);
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/openai_code.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export async function translate(text, from, to, setText, id) {
const { done, value } = await reader.read();
if (done) {
if (translateID.includes(id)) {
setText(target);
setText(target.trim());
}
break;
}
Expand Down Expand Up @@ -152,7 +152,7 @@ export async function translate(text, from, to, setText, id) {
target = target.slice(0, -1);
}
if (translateID.includes(id)) {
setText(target);
setText(target.trim());
}
} else {
throw JSON.stringify(choices);
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/openai_polish.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export async function translate(text, from, to, setText, id) {
const { done, value } = await reader.read();
if (done) {
if (translateID.includes(id)) {
setText(target);
setText(target.trim());
}
break;
}
Expand Down Expand Up @@ -149,7 +149,7 @@ export async function translate(text, from, to, setText, id) {
target = target.slice(0, -1);
}
if (translateID.includes(id)) {
setText(target);
setText(target.trim());
}
} else {
throw JSON.stringify(choices);
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/openai_summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export async function translate(text, from, to, setText, id) {
const { done, value } = await reader.read();
if (done) {
if (translateID.includes(id)) {
setText(target);
setText(target.trim());
}
break;
}
Expand Down Expand Up @@ -149,7 +149,7 @@ export async function translate(text, from, to, setText, id) {
target = target.slice(0, -1);
}
if (translateID.includes(id)) {
setText(target);
setText(target.trim());
}
} else {
throw JSON.stringify(choices);
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/tencent.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export async function translate(text, from, to, setText, id) {
}
}
if (translateID.includes(id)) {
setText(Response['TargetText']);
setText(Response['TargetText'].trim());
}
} else {
throw JSON.stringify(result);
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/volcengine.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export async function translate(text, from, to, setText, id) {
last = cur;
}
if (translateID.includes(id)) {
setText(translations);
setText(translations.trim());
}
} else {
throw JSON.stringify(result);
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/xiaoniu.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export async function translate(text, from, to, setText, id) {
}
}
if (translateID.includes(id)) {
setText(result['tgt_text']);
setText(result['tgt_text'].trim());
}
} else {
throw JSON.stringify(result);
Expand Down

0 comments on commit f29a9d3

Please sign in to comment.