From 573bebd7e674fd8a744f08697db4ac243a018441 Mon Sep 17 00:00:00 2001 From: josc146 Date: Sun, 19 Mar 2023 21:44:56 +0800 Subject: [PATCH] feat: direct translation and bidi translation --- src/config.mjs | 2 +- src/content-script/selection-tools/index.mjs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/config.mjs b/src/config.mjs index f64a8db..f3a3b67 100644 --- a/src/config.mjs +++ b/src/config.mjs @@ -71,7 +71,7 @@ export const defaultConfig = { // others - activeSelectionTools: Object.keys(toolsConfig), + activeSelectionTools: Object.keys(toolsConfig).filter((i) => i !== 'translateBidi'), activeSiteAdapters: [ 'bilibili', 'github', diff --git a/src/content-script/selection-tools/index.mjs b/src/content-script/selection-tools/index.mjs index 835cd06..3b7fa07 100644 --- a/src/content-script/selection-tools/index.mjs +++ b/src/content-script/selection-tools/index.mjs @@ -6,6 +6,7 @@ import { QuestionCircle, Translate, Braces, + Globe, } from 'react-bootstrap-icons' import { getPreferredLanguage } from '../../config.mjs' @@ -13,6 +14,14 @@ export const config = { translate: { icon: , label: 'Translate', + genPrompt: async (selection) => { + const preferredLanguage = await getPreferredLanguage() + return `Translate the following into ${preferredLanguage} and only show me the translated content:\n"${selection}"` + }, + }, + translateBidi: { + icon: , + label: 'Translate (Bidirectional)', genPrompt: async (selection) => { const preferredLanguage = await getPreferredLanguage() return (