commit e3f7b5b83bdf0ab5d77844bcac80392fe3de22d3 Author: koizumi.aoi Date: Fri Dec 9 15:26:58 2022 +0000 Moved to its own repo Signed-off-by: Aoi K git-svn-id: file:///srv/svn/repo/suwako/trunk@1 0b558ee1-521d-8b46-a41b-40029c97c055 diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..9d27966 --- /dev/null +++ b/COPYING @@ -0,0 +1,4 @@ +Freedom License v1 (2021年08月17日) + +全く無限的自由です。 +It's infinite freedom. \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..d8543f4 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.076.ne.jp/novaburst/stcli + +go 1.18 diff --git a/main.go b/main.go new file mode 100644 index 0000000..f2cd70a --- /dev/null +++ b/main.go @@ -0,0 +1,59 @@ +// Yet another command-line client for SimplyTranslate +// All Rites Reversed (ĸ) 3188 Aoi Koizumi, Czar of KST, mutefall, shokara + +package main + +import ( + "fmt" + "net/http" + "flag" + "io" + "path/filepath" + "os" +) + +var ( + instanceURL string + engine string + fromLang string + toLang string + text string +) + +func init() { + // Point flags to variables + flag.StringVar(&instanceURL, "i", "https://translate.bus-hit.me/api/translate/", "Instance for SimplyTranslate (default: https://translate.bus-hit.me)") + flag.StringVar(&engine, "e", "google", "Translation engine (default: google)") + flag.StringVar(&fromLang, "f", "auto", "Source language (default: auto)") + flag.StringVar(&toLang, "t", "", "Target language") + flag.StringVar(&text, "T", "", "Text to translate") +} +func main() { + // Start parsing + flag.Parse() + + // Hand-craft the request URL + queryURL := instanceURL + "?engine=" + engine + "&from=" + fromLang + "&to=" + toLang + "&text=" + text + + // Make a request to said URL + resp, err := http.Get(queryURL) + if err != nil { + panic(err) + } + + defer resp.Body.Close() + body, err := io.ReadAll(resp.Body) + output := body + + fmt.Printf("Input: %s \n", text) + fmt.Printf("Output: %s \n", output) +} +func printUsage() { + fmt.Printf("Usage for %s : \n", filepath.Base(os.Args[0])) + fmt.Printf("-e \t Use the specified translation engine (default: google)\n") + fmt.Printf("-f \t (default: auto)\n") + fmt.Printf("-t \t (default: none)\n") + fmt.Printf("-T \t Text to translate\n") + + os.Exit(1) +}