Skip to content

Commit 195c2e8

Browse files
committed
feat: support the polishing of Japanese and other languages
1 parent 5643942 commit 195c2e8

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

src/main.js

+24-13
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,24 @@ function translate(query, completion) {
1212
"Content-Type": "application/json",
1313
Authorization: `Bearer ${api_key}`,
1414
};
15-
let prompt = "";
16-
if (query.detectFrom === "zh-Hant" || query.detectFrom === "zh-Hans") {
17-
prompt = "请润色一下这句话";
18-
} else {
19-
prompt = "please polish this sentence";
15+
let prompt = "please polish this sentence";
16+
switch (query.detectFrom) {
17+
case "zh-Hant":
18+
case "zh-Hans":
19+
prompt = "请润色一下这句话";
20+
break;
21+
case "ja":
22+
prompt = "この文章を装飾してください";
23+
break;
24+
case "ru":
25+
prompt = "Пожалуйста, приукрасьте это предложение";
26+
break;
27+
case "wyw":
28+
prompt = "请润色一下这句古文";
29+
break;
30+
case "yue":
31+
prompt = "请润色一下这句粤语";
32+
break;
2033
}
2134
const body = {
2235
model: $option.model,
@@ -30,7 +43,7 @@ function translate(query, completion) {
3043
if (isChatGPTModel) {
3144
body.messages = [
3245
{ role: "system", content: prompt },
33-
{ role: "user", content: query.text },
46+
{ role: "user", content: `"${query.text}"` },
3447
];
3548
} else {
3649
body.prompt = `${prompt}:\n\n"${query.text}" =>`;
@@ -76,13 +89,11 @@ function translate(query, completion) {
7689
} else {
7790
targetTxt = choices[0].text.trim();
7891
}
79-
if (!isChatGPTModel) {
80-
if (targetTxt.startsWith('"')) {
81-
targetTxt = targetTxt.slice(1);
82-
}
83-
if (targetTxt.endsWith('"')) {
84-
targetTxt = targetTxt.slice(0, -1);
85-
}
92+
if (targetTxt.startsWith('"') || targetTxt.startsWith("「")) {
93+
targetTxt = targetTxt.slice(1);
94+
}
95+
if (targetTxt.endsWith('"') || targetTxt.endsWith("」")) {
96+
targetTxt = targetTxt.slice(0, -1);
8697
}
8798
completion({
8899
result: {

0 commit comments

Comments
 (0)