upload to github

This commit is contained in:
potassium 2023-05-15 16:32:45 +03:00
commit fb483965b2
3 changed files with 52 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
translate

8
go.sum Normal file
View File

@ -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=

43
main.go Normal file
View File

@ -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)
}