From 2e8911db573dd0915973abb1cceb0023fd417663 Mon Sep 17 00:00:00 2001 From: AiraNadih <128119996+AiraNadih@users.noreply.github.com> Date: Thu, 21 Dec 2023 13:26:55 +0800 Subject: [PATCH] refactor(selection-tools): remove redundant `getPreferredLanguage` calls (#593) --- src/content-script/selection-tools/index.mjs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/content-script/selection-tools/index.mjs b/src/content-script/selection-tools/index.mjs index d82a68f8..71acf8af 100644 --- a/src/content-script/selection-tools/index.mjs +++ b/src/content-script/selection-tools/index.mjs @@ -20,7 +20,12 @@ const createGenPrompt = includeLanguagePrefix = false, }) => async (selection) => { - const preferredLanguage = isTranslation ? targetLanguage : await getPreferredLanguage() + let preferredLanguage = targetLanguage + + if (!preferredLanguage) { + preferredLanguage = await getPreferredLanguage() + } + let fullMessage = isTranslation ? `Translate the following into ${preferredLanguage} and only show me the translated content` : message @@ -45,7 +50,6 @@ export const config = { label: 'Translate', genPrompt: createGenPrompt({ isTranslation: true, - targetLanguage: await getPreferredLanguage(), }), }, translateToEn: { @@ -69,7 +73,6 @@ export const config = { label: 'Translate (Bidirectional)', genPrompt: createGenPrompt({ isTranslation: true, - targetLanguage: await getPreferredLanguage(), enableBidirectional: true, }), },