Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
remove selected text translation
Browse files Browse the repository at this point in the history
  • Loading branch information
theowenyoung committed Nov 15, 2022
1 parent db1ff20 commit 3dcd285
Show file tree
Hide file tree
Showing 21 changed files with 181 additions and 2,495 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
## 0.0.25

- Support gist.github.com
- Support slack.com
- Fix 1paragraph.app epub adapt

### Break Changes

- Remove select text to translate, now the extension is focus on web page translate
- Better for Options

## 0.0.24

Expand Down
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ gulp.task("chrome-babel", () => {
});

gulp.task("chrome-concat-background",()=>{
return gulp.src(["/lib/languages.js", "/lib/config.js", "/lib/platformInfo.js","/lib/util.js", "/background/translationCache.js", "/background/translationService.js", "/background/textToSpeech.js", "/background/chrome_background.js"].map(item=>"dist/chrome"+item))
return gulp.src(["/lib/languages.js", "/lib/config.js", "/lib/platformInfo.js","/lib/util.js", "/background/translationCache.js", "/background/translationService.js", "/background/chrome_background.js"].map(item=>"dist/chrome"+item))
.pipe(concat('background-entry.js'))
.pipe(gulp.dest('dist/chrome/background'));
})
Expand Down
14 changes: 8 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Let's experience immersive web translation, with bilingual simultaneous display
- 支持PDF文件双语对照翻译(pdf文件翻译需要点击浏览器右上角的该扩展图标,弹出提示框后按提示框操作)
- 配合epub在线阅读网站<https://1paragraph.app/> 即可实现双语阅读国外电子书

> 已删除原扩展选中文本翻译功能,此扩展现在仅 Focus 网页翻译。划词翻译功能请使用其他同类产品~
**视频介绍**

[![Demo](https://img.youtube.com/vi/9TzX0xEBmyw/0.jpg)](https://www.youtube.com/watch?v=9TzX0xEBmyw)
Expand All @@ -32,7 +34,7 @@ Let's experience immersive web translation, with bilingual simultaneous display
- 希望同时显示双语,以平衡部分机器翻译的不知所云
- 希望尽快摆脱这个扩展,直接习惯看原文的用户的过渡助手

该扩展同时支持(依赖)谷歌翻译引擎或Yandex翻译引擎,同时也支持使用Bing,Deepl进行文本选中翻译,完全免费,希望我们都能尽可能平等的获取知识,不要让语言成为障碍,感谢[原作者](https://github.com/FilipePS/Traduzir-paginas-web)为这个项目付出的巨大努力。
该扩展同时支持(依赖)谷歌翻译引擎或Yandex翻译引擎,完全免费,希望我们都能尽可能平等的获取知识,不要让语言成为障碍,感谢[原作者](https://github.com/FilipePS/Traduzir-paginas-web)为这个项目付出的巨大努力。

本项目的[Wiki页面](https://github.com/immersive-translate/immersive-translate/wiki)下有更多使用帮助信息。

Expand Down Expand Up @@ -86,7 +88,7 @@ Google翻译会调用该接口: `https://translate.googleapis.com/translate_a/

目前已有的规则见[这里](https://github.com/immersive-translate/immersive-translate/blob/main/src/lib/specialRules.js)

你可以点击浏览器该扩展图标 -> 选项(进入扩展配置页面) -> 网站配置 -> 特殊页面翻译规则 来进入页面规则配置
你可以点击浏览器该扩展图标 -> 选项(进入扩展配置), 滑动到最后,即可看到特殊页面规则配置

一个基本的配置规则如下:

Expand All @@ -105,7 +107,7 @@ Google翻译会调用该接口: `https://translate.googleapis.com/translate_a/

### 双语显示样式配置

默认的双语显示没有添加任何样式,但是我们提供了内置的几种样式可供选择,你可以从`配置->样式->双语显示主题配置`来更改样式,比如下划线样式长这样:
默认的双语显示没有添加任何样式,但是我们提供了内置的几种样式可供选择,你可以从`配置->常用配置->双语显示主题配置`来更改样式,比如下划线样式长这样:

![twitter](assets/twitter.png)

Expand Down Expand Up @@ -215,9 +217,9 @@ Some pages like [support.mozilla.org](https://support.mozilla.org/) and [addons.

- [x] - adapt for Github
- [x] - backup默认文件名还是TWP
- [ ] - option页面从extension中打开的显示问题
- [x] - option页面从extension中打开的显示问题
- [x] - 版本号自动添加
- [x] - youtube comments
- [x] - better for github
- [ ] - check is target language, if so ,do not translate
- [ ] - read mode
- [x] - check is target language, if so ,do not translate
- [x] - read mode
7 changes: 5 additions & 2 deletions src/_locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@
"message": "翻译页面为目标语言"
},
"lblTranslateTag_pre": {
"message": "启用对 $HTML_TAG_NAME$ 标签的翻译",
"message": "启用对 $HTML_TAG_NAME$ 标签(常用于代码块)的翻译",
"placeholders": {
"HTML_TAG_NAME": {
"content": "<PRE>"
Expand All @@ -383,7 +383,7 @@
"message": "不对 Google 翻译结果进行排序"
},
"lbltranslatedynamicallycreatedcontent": {
"message": "翻译动态创建的内容"
"message": "是否翻译加载更多后的内容"
},
"calculatestorage": {
"message": "计算"
Expand Down Expand Up @@ -525,6 +525,9 @@
},
"lblTelegram":{
"message": "加Telegram群"
},
"msgCommon":{
"message":"常用配置"
}

}
4 changes: 4 additions & 0 deletions src/_locales/zh_TW/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,10 @@
},
"lblTelegram":{
"message": "加Telegram群"
},
"msgCommon":{
"message":"常用設置"
}


}
100 changes: 4 additions & 96 deletions src/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,6 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
}
})

function updateTranslateSelectedContextMenu() {
if (typeof chrome.contextMenus !== "undefined") {
chrome.contextMenus.remove("translate-selected-text", checkedLastError)
if (twpConfig.get("showTranslateSelectedContextMenu") === "yes") {
chrome.contextMenus.create({
id: "translate-selected-text",
title: chrome.i18n.getMessage("msgTranslateSelectedText"),
contexts: ["selection"]
})
}
}
}

function updateContextMenu(pageLanguageState = "original") {
let contextMenuTitle
Expand Down Expand Up @@ -249,22 +237,6 @@ if (typeof chrome.contextMenus !== "undefined") {
action: "toggle-translation"
}, checkedLastError)
}
} else if (info.menuItemId == "translate-selected-text") {
if (chrome.pageAction && chrome.pageAction.openPopup && (!tabHasContentScript[tab.id] || tab.isInReaderMode)) {
chrome.pageAction.setPopup({
popup: "popup/popup-translate-text.html#text=" + encodeURIComponent(info.selectionText),
tabId: tab.id
})
chrome.pageAction.openPopup()

resetPageAction(tab.id)
} else {
// a merda do chrome não suporte openPopup
chrome.tabs.sendMessage(tab.id, {
action: "TranslateSelectedText",
selectionText: info.selectionText
}, checkedLastError)
}
} else if (info.menuItemId == "browserAction-showPopup") {
resetBrowserAction(true)

Expand Down Expand Up @@ -525,6 +497,7 @@ twpConfig.onReady(() => {

if (typeof chrome.commands !== "undefined") {
chrome.commands.onCommand.addListener(command => {
console.log("command", command)
if (command === "hotkey-toggle-translation") {
chrome.tabs.query({
currentWindow: true,
Expand All @@ -534,14 +507,6 @@ if (typeof chrome.commands !== "undefined") {
action: "toggle-translation"
}, checkedLastError)
})
} else if (command === "hotkey-translate-selected-text") {
chrome.tabs.query({
currentWindow: true,
active: true
}, tabs =>
chrome.tabs.sendMessage(tabs[0].id, {
action: "TranslateSelectedText"
}, checkedLastError))
} else if (command === "hotkey-swap-page-translation-service") {
chrome.tabs.query({
active: true,
Expand All @@ -559,72 +524,15 @@ if (typeof chrome.commands !== "undefined") {
}

twpConfig.set("pageTranslatorService", currentPageTranslatorService)
} else if (command === "hotkey-show-original") {
chrome.tabs.query({
active: true,
currentWindow: true
}, tabs =>
chrome.tabs.sendMessage(tabs[0].id, {
action: "translatePage",
targetLanguage: "original"
}, checkedLastError))
} else if (command === "hotkey-translate-page-1") {
chrome.tabs.query({
active: true,
currentWindow: true
}, tabs => {
twpConfig.setTargetLanguage(twpConfig.get("targetLanguages")[0])
chrome.tabs.sendMessage(tabs[0].id, {
action: "translatePage",
targetLanguage: twpConfig.get("targetLanguages")[0]
}, checkedLastError)
})
} else if (command === "hotkey-translate-page-2") {
chrome.tabs.query({
active: true,
currentWindow: true
}, tabs => {
twpConfig.setTargetLanguage(twpConfig.get("targetLanguages")[1])
chrome.tabs.sendMessage(tabs[0].id, {
action: "translatePage",
targetLanguage: twpConfig.get("targetLanguages")[1]
}, checkedLastError)
})
} else if (command === "hotkey-translate-page-3") {
chrome.tabs.query({
active: true,
currentWindow: true
}, tabs => {
twpConfig.setTargetLanguage(twpConfig.get("targetLanguages")[2])
chrome.tabs.sendMessage(tabs[0].id, {
action: "translatePage",
targetLanguage: twpConfig.get("targetLanguages")[2]
}, checkedLastError)
})
} else if (command === "hotkey-hot-translate-selected-text") {
chrome.tabs.query({
active: true,
currentWindow: true
}, tabs => {
chrome.tabs.sendMessage(tabs[0].id, {
action: "hotTranslateSelectedText"
}, checkedLastError)
})
}
}

})
}

twpConfig.onReady(async () => {
updateContextMenu()
updateTranslateSelectedContextMenu()

twpConfig.onChanged((name, newvalue) => {
if (name === "showTranslateSelectedContextMenu") {
updateTranslateSelectedContextMenu()
}
})

if (!twpConfig.get("installDateTime")) {
if (!twpConfig.get("installDateTime")) {
twpConfig.set("installDateTime", Date.now())
}
})
Expand Down
97 changes: 2 additions & 95 deletions src/background/chrome_background.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {

})

function updateTranslateSelectedContextMenu() {
if (typeof chrome.contextMenus !== "undefined") {
chrome.contextMenus.remove("translate-selected-text", checkedLastError)
if (twpConfig.get("showTranslateSelectedContextMenu") === "yes") {
chrome.contextMenus.create({
id: "translate-selected-text",
title: chrome.i18n.getMessage("msgTranslateSelectedText"),
contexts: ["selection"]
})
}
}
}


function updateContextMenu(pageLanguageState = "original") {
let contextMenuTitle
Expand Down Expand Up @@ -249,23 +238,6 @@ if (typeof chrome.contextMenus !== "undefined") {
action: "toggle-translation"
}, checkedLastError)
}
} else if (info.menuItemId == "translate-selected-text") {
if (chrome.action && chrome.action.openPopup && (!tabHasContentScript[tab.id] || tab.isInReaderMode)) {

chrome.action.setPopup({
popup: "popup/popup-translate-text.html#text=" + encodeURIComponent(info.selectionText),
tabId: tab.id
})
chrome.action.openPopup()

resetPageAction(tab.id)
} else {
// a merda do chrome não suporte openPopup
chrome.tabs.sendMessage(tab.id, {
action: "TranslateSelectedText",
selectionText: info.selectionText
}, checkedLastError)
}
} else if (info.menuItemId == "browserAction-showPopup") {
resetBrowserAction(true)

Expand Down Expand Up @@ -535,14 +507,6 @@ if (typeof chrome.commands !== "undefined") {
action: "toggle-translation"
}, checkedLastError)
})
} else if (command === "hotkey-translate-selected-text") {
chrome.tabs.query({
currentWindow: true,
active: true
}, tabs =>
chrome.tabs.sendMessage(tabs[0].id, {
action: "TranslateSelectedText"
}, checkedLastError))
} else if (command === "hotkey-swap-page-translation-service") {
chrome.tabs.query({
active: true,
Expand All @@ -560,70 +524,13 @@ if (typeof chrome.commands !== "undefined") {
}

twpConfig.set("pageTranslatorService", currentPageTranslatorService)
} else if (command === "hotkey-show-original") {
chrome.tabs.query({
active: true,
currentWindow: true
}, tabs =>
chrome.tabs.sendMessage(tabs[0].id, {
action: "translatePage",
targetLanguage: "original"
}, checkedLastError))
} else if (command === "hotkey-translate-page-1") {
chrome.tabs.query({
active: true,
currentWindow: true
}, tabs => {
twpConfig.setTargetLanguage(twpConfig.get("targetLanguages")[0])
chrome.tabs.sendMessage(tabs[0].id, {
action: "translatePage",
targetLanguage: twpConfig.get("targetLanguages")[0]
}, checkedLastError)
})
} else if (command === "hotkey-translate-page-2") {
chrome.tabs.query({
active: true,
currentWindow: true
}, tabs => {
twpConfig.setTargetLanguage(twpConfig.get("targetLanguages")[1])
chrome.tabs.sendMessage(tabs[0].id, {
action: "translatePage",
targetLanguage: twpConfig.get("targetLanguages")[1]
}, checkedLastError)
})
} else if (command === "hotkey-translate-page-3") {
chrome.tabs.query({
active: true,
currentWindow: true
}, tabs => {
twpConfig.setTargetLanguage(twpConfig.get("targetLanguages")[2])
chrome.tabs.sendMessage(tabs[0].id, {
action: "translatePage",
targetLanguage: twpConfig.get("targetLanguages")[2]
}, checkedLastError)
})
} else if (command === "hotkey-hot-translate-selected-text") {
chrome.tabs.query({
active: true,
currentWindow: true
}, tabs => {
chrome.tabs.sendMessage(tabs[0].id, {
action: "hotTranslateSelectedText"
}, checkedLastError)
})
}
}
})
}

twpConfig.onReady(async () => {
updateContextMenu()
updateTranslateSelectedContextMenu()

twpConfig.onChanged((name, newvalue) => {
if (name === "showTranslateSelectedContextMenu") {
updateTranslateSelectedContextMenu()
}
})

if (!twpConfig.get("installDateTime")) {
twpConfig.set("installDateTime", Date.now())
Expand Down
Loading

0 comments on commit 3dcd285

Please sign in to comment.