
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
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
// 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)
|
|
}
|