Skip to content

Commit 2fc0b57

Browse files
committed
patch to #564
1 parent e5ebd45 commit 2fc0b57

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

src/content-script/selection-tools/index.mjs

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,78 +17,76 @@ const createGenPrompt =
1717
isTranslation = false,
1818
targetLanguage = '',
1919
enableBidirectional = false,
20-
includeLanguagePrefix = false
20+
includeLanguagePrefix = false,
2121
}) =>
22-
async (selection) => {
23-
const preferredLanguage = isTranslation
24-
? targetLanguage
25-
: await getPreferredLanguage()
26-
let fullMessage = isTranslation
27-
? `Translate the following into ${preferredLanguage} and only show me the translated content`
28-
: message
29-
if (enableBidirectional) {
30-
fullMessage += `. If it is already in ${preferredLanguage}, translate it into English and only show me the translated content`
31-
}
32-
const prefix = includeLanguagePrefix
33-
? `Reply in ${preferredLanguage}.`
34-
: ''
35-
return `${prefix}${fullMessage}:\n'''\n${selection}\n'''`
22+
async (selection) => {
23+
const preferredLanguage = isTranslation ? targetLanguage : await getPreferredLanguage()
24+
let fullMessage = isTranslation
25+
? `Translate the following into ${preferredLanguage} and only show me the translated content`
26+
: message
27+
if (enableBidirectional) {
28+
fullMessage += `. If it is already in ${preferredLanguage}, translate it into English and only show me the translated content`
3629
}
30+
const prefix = includeLanguagePrefix ? `Reply in ${preferredLanguage}.` : ''
31+
return `${prefix}${fullMessage}:\n'''\n${selection}\n'''`
32+
}
3733

3834
export const config = {
3935
explain: {
4036
icon: <ChatText />,
4137
label: 'Explain',
4238
genPrompt: createGenPrompt({
4339
message: 'Explain the following',
44-
includeLanguagePrefix: true
40+
includeLanguagePrefix: true,
4541
}),
4642
},
4743
translate: {
4844
icon: <Translate />,
4945
label: 'Translate',
5046
genPrompt: createGenPrompt({
51-
isTranslation: true
47+
isTranslation: true,
48+
targetLanguage: await getPreferredLanguage(),
5249
}),
5350
},
5451
translateToEn: {
5552
icon: <Globe />,
5653
label: 'Translate (To English)',
5754
genPrompt: createGenPrompt({
5855
isTranslation: true,
59-
targetLanguage: 'English'
56+
targetLanguage: 'English',
6057
}),
6158
},
6259
translateToZh: {
6360
icon: <Globe />,
6461
label: 'Translate (To Chinese)',
6562
genPrompt: createGenPrompt({
6663
isTranslation: true,
67-
targetLanguage: 'Chinese'
64+
targetLanguage: 'Chinese',
6865
}),
6966
},
7067
translateBidi: {
7168
icon: <Globe />,
7269
label: 'Translate (Bidirectional)',
7370
genPrompt: createGenPrompt({
7471
isTranslation: true,
75-
enableBidirectional: true
72+
targetLanguage: await getPreferredLanguage(),
73+
enableBidirectional: true,
7674
}),
7775
},
7876
summary: {
7977
icon: <CardHeading />,
8078
label: 'Summary',
8179
genPrompt: createGenPrompt({
8280
message: 'Summarize the following as concisely as possible',
83-
includeLanguagePrefix: true
81+
includeLanguagePrefix: true,
8482
}),
8583
},
8684
polish: {
8785
icon: <Palette />,
8886
label: 'Polish',
8987
genPrompt: createGenPrompt({
9088
message:
91-
'Check the following content for possible diction and grammar problems, and polish it carefully'
89+
'Check the following content for possible diction and grammar problems, and polish it carefully',
9290
}),
9391
},
9492
sentiment: {
@@ -97,32 +95,30 @@ export const config = {
9795
genPrompt: createGenPrompt({
9896
message:
9997
'Analyze the sentiments expressed in the following content and make a brief summary of the sentiments',
100-
includeLanguagePrefix: true
98+
includeLanguagePrefix: true,
10199
}),
102100
},
103101
divide: {
104102
icon: <CardList />,
105103
label: 'Divide Paragraphs',
106104
genPrompt: createGenPrompt({
107-
message:
108-
'Divide the following into paragraphs that are easy to read and understand'
105+
message: 'Divide the following into paragraphs that are easy to read and understand',
109106
}),
110107
},
111108
code: {
112109
icon: <Braces />,
113110
label: 'Code Explain',
114111
genPrompt: createGenPrompt({
115112
message: 'Explain the following code',
116-
includeLanguagePrefix: true
113+
includeLanguagePrefix: true,
117114
}),
118115
},
119116
ask: {
120117
icon: <QuestionCircle />,
121118
label: 'Ask',
122119
genPrompt: createGenPrompt({
123-
message:
124-
'Analyze the following content and express your opinion, or give your answer',
125-
includeLanguagePrefix: true
120+
message: 'Analyze the following content and express your opinion, or give your answer',
121+
includeLanguagePrefix: true,
126122
}),
127123
},
128124
}

0 commit comments

Comments
 (0)