Moved to its own repo
Signed-off-by: Aoi K <koizumi.aoi@kyoko-project.wer.ee> git-svn-id: file:///srv/svn/repo/suwako/trunk@1 0b558ee1-521d-8b46-a41b-40029c97c055
This commit is contained in:
commit
e3f7b5b83b
4
COPYING
Normal file
4
COPYING
Normal file
@ -0,0 +1,4 @@
|
||||
Freedom License v1 (2021年08月17日)
|
||||
|
||||
全く無限的自由です。
|
||||
It's infinite freedom.
|
59
main.go
Normal file
59
main.go
Normal file
@ -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)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user