Skip to content

Commit

Permalink
更新自动识别语言翻译为中文, YouDao Translate的不怎么好, 推荐使用默认Google Translate
Browse files Browse the repository at this point in the history
  • Loading branch information
cnbattle committed Apr 25, 2020
1 parent a293205 commit dc54323
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -11,7 +11,7 @@
|![](screenshots/linux.png)|![](screenshots/windows10.png)|

## 特色
- 自动翻译 `clipboard` 为英语的内容
- 自动翻译 `clipboard` 的内容
- 支持 `Google Translate``YouDao Translate`
- 开源,不用担心 `clipboard` 内容泄漏问题

Expand Down
13 changes: 1 addition & 12 deletions aitranslate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
4 changes: 0 additions & 4 deletions translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"github.com/cnbattle/aitranslate/translate"
"github.com/cnbattle/aitranslate/whatlang"
"github.com/gen2brain/beeep"
"strings"
"time"
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion translate/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion translate/youdao.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dc54323

Please sign in to comment.