From 72dcdf4826a0b5915ac8fb14e3df761d66ec3afe Mon Sep 17 00:00:00 2001 From: josc146 Date: Fri, 21 Apr 2023 20:17:58 +0800 Subject: [PATCH] feat: new selection tool `translate to english` (#240) --- src/_locales/en/main.json | 1 + src/_locales/zh-hans/main.json | 1 + src/_locales/zh-hant/main.json | 1 + src/config/index.mjs | 2 ++ src/content-script/selection-tools/index.mjs | 11 +++++++++-- 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/_locales/en/main.json b/src/_locales/en/main.json index 8c1a7be..c22e405 100644 --- a/src/_locales/en/main.json +++ b/src/_locales/en/main.json @@ -54,6 +54,7 @@ "Summarize Page": "Summarize Page", "Translate": "Translate", "Translate (Bidirectional)": "Translate (Bidirectional)", + "Translate (To English)": "Translate (To English)", "Summary": "Summary", "Polish": "Polish", "Sentiment Analysis": "Sentiment Analysis", diff --git a/src/_locales/zh-hans/main.json b/src/_locales/zh-hans/main.json index b5f8df8..b78a99e 100644 --- a/src/_locales/zh-hans/main.json +++ b/src/_locales/zh-hans/main.json @@ -54,6 +54,7 @@ "Summarize Page": "总结本页", "Translate": "翻译", "Translate (Bidirectional)": "双向翻译", + "Translate (To English)": "翻译为英语", "Summary": "总结", "Polish": "润色", "Sentiment Analysis": "情感分析", diff --git a/src/_locales/zh-hant/main.json b/src/_locales/zh-hant/main.json index c86d338..85282c5 100644 --- a/src/_locales/zh-hant/main.json +++ b/src/_locales/zh-hant/main.json @@ -54,6 +54,7 @@ "Summarize Page": "摘要本頁", "Translate": "翻譯", "Translate (Bidirectional)": "雙向翻譯", + "Translate (To English)": "翻譯為英語", "Summary": "摘要", "Polish": "潤色", "Sentiment Analysis": "情感分析", diff --git a/src/config/index.mjs b/src/config/index.mjs index 2971573..1b85dd5 100644 --- a/src/config/index.mjs +++ b/src/config/index.mjs @@ -134,6 +134,7 @@ export const defaultConfig = { userLanguage: getNavigatorLanguage(), selectionTools: [ 'translate', + 'translateToEn', 'translateBidi', 'summary', 'polish', @@ -144,6 +145,7 @@ export const defaultConfig = { ], selectionToolsDesc: [ 'Translate', + 'Translate (To English)', 'Translate (Bidirectional)', 'Summary', 'Polish', diff --git a/src/content-script/selection-tools/index.mjs b/src/content-script/selection-tools/index.mjs index 4e50010..c29a2a1 100644 --- a/src/content-script/selection-tools/index.mjs +++ b/src/content-script/selection-tools/index.mjs @@ -16,7 +16,14 @@ export const config = { label: 'Translate', genPrompt: async (selection) => { const preferredLanguage = await getPreferredLanguage() - return `Translate the following into ${preferredLanguage} and only show me the translated content:\n"${selection}"` + return `Translate the following into ${preferredLanguage} and only show me the translated content:\n${selection}` + }, + }, + translateToEn: { + icon: , + label: 'Translate (To English)', + genPrompt: async (selection) => { + return `Translate the following into English and only show me the translated content:\n${selection}` }, }, translateBidi: { @@ -27,7 +34,7 @@ export const config = { return ( `Translate the following into ${preferredLanguage} and only show me the translated content.` + `If it is already in ${preferredLanguage},` + - `translate it into English and only show me the translated content:\n"${selection}"` + `translate it into English and only show me the translated content:\n${selection}` ) }, },