From fb483965b2f42171c6fd8046518d3fbe26268b0c Mon Sep 17 00:00:00 2001 From: potassium Date: Mon, 15 May 2023 16:32:45 +0300 Subject: [PATCH] upload to github --- .gitignore | 1 + go.sum | 8 ++++++++ main.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 .gitignore create mode 100644 go.sum create mode 100644 main.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0671813 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +translate diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..fe2d799 --- /dev/null +++ b/go.sum @@ -0,0 +1,8 @@ +github.com/bas24/googletranslatefree v0.0.0-20220326200502-05ed9e639439 h1:oW1ixF7R47ZbPplnJY7oygLHnB7X+wsbj4jP79IWwv0= +github.com/bas24/googletranslatefree v0.0.0-20220326200502-05ed9e639439/go.mod h1:ntTdGCe6WzFmHjox8vK2FZ2KLyh0IFxw43B6XCg0zf4= +github.com/robertkrimen/otto v0.2.1 h1:FVP0PJ0AHIjC+N4pKCG9yCDz6LHNPCwi/GKID5pGGF0= +github.com/robertkrimen/otto v0.2.1/go.mod h1:UPwtJ1Xu7JrLcZjNWN8orJaM5n5YEtqL//farB5FlRY= +golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +gopkg.in/sourcemap.v1 v1.0.5 h1:inv58fC9f9J3TK2Y2R1NPntXEn3/wjWHkonhIUODNTI= +gopkg.in/sourcemap.v1 v1.0.5/go.mod h1:2RlvNNSMglmRrcvhfuzp4hQHwOtjxlbjX7UPY/GXb78= diff --git a/main.go b/main.go new file mode 100644 index 0000000..52850ec --- /dev/null +++ b/main.go @@ -0,0 +1,43 @@ +// test of github.com/bas24/googletranslate +package main + +import ( + "io" + "os" + + gt "github.com/bas24/googletranslatefree" + + "flag" + "fmt" + "strings" +) + +func main() { + english := flag.Bool("en", false, "translate from english") + var source, into string = "ru", "en" + var text interface{} + var err error + + flag.Parse() + Args := flag.Args() + if len(Args) > 0 { + text = strings.Join(Args[:], " ") + } else { + text, err = io.ReadAll(os.Stdin) + if err != nil { + panic(err) + } + if len(text.([]byte)) == 0 { + os.Exit(1) + } + text = string(text.([]byte)) // looks awful but it works + } + if *english { + source, into = into, source + } + result, err := gt.Translate(text.(string), source, into) + if err != nil { + panic(err) + } + fmt.Println(result) +}