From dc5432372005ed2176687c05f73d1edd3e96b110 Mon Sep 17 00:00:00 2001 From: cnbattle Date: Sat, 25 Apr 2020 09:23:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=87=AA=E5=8A=A8=E8=AF=86?= =?UTF-8?q?=E5=88=AB=E8=AF=AD=E8=A8=80=E7=BF=BB=E8=AF=91=E4=B8=BA=E4=B8=AD?= =?UTF-8?q?=E6=96=87,=20YouDao=20Translate=E7=9A=84=E4=B8=8D=E6=80=8E?= =?UTF-8?q?=E4=B9=88=E5=A5=BD,=20=E6=8E=A8=E8=8D=90=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E9=BB=98=E8=AE=A4Google=20Translate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- aitranslate.go | 13 +------------ translate.go | 4 ---- translate/google.go | 2 +- translate/youdao.go | 2 +- 5 files changed, 5 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 041243f..d32cd14 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![LICENSE](https://img.shields.io/badge/license-Anti%20996-blue.svg?style=flat-square)](https://github.com/996icu/996.ICU/blob/master/LICENSE) -> 监听粘贴版新的英文内容并翻译成中文 +> 监听粘贴版新的内容并翻译成中文 > 仅在`Manjaro`/ `Windows 10`上测试,`Mac`等其他平台未知,有问题或建议请提交`Pull Requests`或`Issues` @@ -11,7 +11,7 @@ |![](screenshots/linux.png)|![](screenshots/windows10.png)| ## 特色 - - 自动翻译 `clipboard` 为英语的内容 + - 自动翻译 `clipboard` 的内容 - 支持 `Google Translate` 和 `YouDao Translate` - 开源,不用担心 `clipboard` 内容泄漏问题 diff --git a/aitranslate.go b/aitranslate.go index 5175bdb..89082c9 100644 --- a/aitranslate.go +++ b/aitranslate.go @@ -2,36 +2,25 @@ package main import ( "flag" - "fmt" ) var ( - // 版本号 - Version string // 翻译渠道 channel string // 待翻译的文本 text string // 通知logo path string - // 是否显示版本号 - v bool // 监听时间间隔 - monitoringInterval int + monitoringInterval int = 100 ) func init() { initFile() flag.StringVar(&channel, "c", "Google", "translate channel: Google or YouDao.") - flag.IntVar(&monitoringInterval, "t", 100, "monitoring interval, unit: ms.") - flag.BoolVar(&v, "v", false, "show version and exit.") flag.Parse() } func main() { - if v { - fmt.Println(Version) - return - } translates() } diff --git a/translate.go b/translate.go index 9a5baae..d808dec 100644 --- a/translate.go +++ b/translate.go @@ -2,7 +2,6 @@ package main import ( "github.com/cnbattle/aitranslate/translate" - "github.com/cnbattle/aitranslate/whatlang" "github.com/gen2brain/beeep" "strings" "time" @@ -15,9 +14,6 @@ func translates() { for { time.Sleep(time.Millisecond * time.Duration(monitoringInterval)) newText := getClipboardString() - if !whatlang.IsEnglish(newText) { - continue - } if !strings.EqualFold(text, newText) { text = newText translateText, err := translate.Trans(channel, text) diff --git a/translate/google.go b/translate/google.go index acbd3d4..3f33d75 100644 --- a/translate/google.go +++ b/translate/google.go @@ -10,7 +10,7 @@ import ( type googleTranslate struct{} func (g googleTranslate) Trans(text string) (str string, err error) { - urlStr := "http://translate.google.cn/translate_a/single?client=gtx&sl=en&tl=zh-CN&dt=t&q=" + text + urlStr := "http://translate.google.cn/translate_a/single?client=gtx&sl=auto&tl=zh-CN&&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&q=" + text body, err := utils.HttpGet(urlStr) if err != nil { return "", err diff --git a/translate/youdao.go b/translate/youdao.go index 796689a..2a8a261 100644 --- a/translate/youdao.go +++ b/translate/youdao.go @@ -21,7 +21,7 @@ type translateResult struct { } func (g youDaoTranslate) Trans(text string) (resText string, err error) { - urlStr := "http://fanyi.youdao.com/translate?&doctype=json&type=EN2ZH_CN&i=" + text + urlStr := "http://fanyi.youdao.com/translate?&doctype=json&type=AUTO2ZH_CN&i=" + text body, err := utils.HttpGet(urlStr) if err != nil { return "", err