Legend:
- Unmodified
- Added
- Removed
-
trunk/Makefile
r3 r5 1 PREFIX=/usr/local 2 1 3 build: 2 4 go build 3 5 clean: 4 6 rm -f stcli-go 7 install: build 8 install -Dm0755 stcli-go ${PREFIX}/bin/stcli-go 9 uninstall: 10 rm -f ${PREFIX}/bin/stcli-go 11 rm -f ${PREFIX}/share/man/man1/stcli-go.1 -
trunk/main.go
r4 r5 1 // $KyokoNet: stcli-go,v 1.1 2022/12/13 10:07:00 akoizumi Exp 2 // Command line client for SimplyTranslate, a privacy friendly frontend to Google Translate 1 3 package main 2 4 … … 10 12 "os" 11 13 ) 12 13 14 var ( 14 instanceURLstring15 enginestring16 fromLangstring17 toLangstring18 t extstring15 engine string 16 from string 17 instance string 18 input string 19 to string 19 20 ) 20 21 type TranslateAPI struct { 22 OutText string `json:"translated-text"` 21 type Translate struct { 22 Output string `json:"translated-text"` 23 23 } 24 25 24 func init() { 26 flag.StringVar(& instanceURL, "i", "https://translate.bus-hit.me/api/translate/", "Instance for SimplyTranslate (default: https://translate.bus-hit.me)")27 flag.StringVar(& engine, "e", "google", "Translation engine (default: google)")28 flag.StringVar(& fromLang, "f", "auto", "Source language (default: auto)")29 flag.StringVar(& toLang, "t", "", "Target language (default: unset)")30 flag.StringVar(&t ext, "T", "", "Text to translate (default: unset)")25 flag.StringVar(&engine, "e", "google", "Translation engine to use (default: google)") 26 flag.StringVar(&from, "f", "auto", "Set the language to translate from. This can be skipped as it will autodetect the language you're translating from") 27 flag.StringVar(&instance, "i", "https://simplytranslate.org/api/translate/", "Instance to use (default: https://simplytranslate.org/api/translate/)") 28 flag.StringVar(&input, "I", "", "Enter the text to be translated") 29 flag.StringVar(&to, "t", "en", "Set the language to translate to (default: en)") 31 30 } 32 31 func main() { 32 // Begin flag parsing 33 33 flag.Parse() 34 if len(text) == 0 || len(toLang) == 0 { 34 // Check if any of those two variables is empty. 35 // It actually needs the two to have content. 36 if len(input) == 0 || len(to) == 0 { 35 37 log.Fatal("Missing either the text or the target language.") 36 38 os.Exit(1) 37 39 } 38 var o TranslateAPI 39 var queryURL = instanceURL + "?engine=" + engine + "&from=" + fromLang + "&to=" + toLang + "&text=" + text 40 // Map a variable to the struct 41 var translate Translate 42 // Build the full URL to query 43 var queryURL = instance + "?engine=" + engine + "&from=" + from + "&to=" + to + "&text=" + input 44 // Begin the request and process the response 40 45 req, err := http.Get(queryURL) 41 46 sanityCheck(err) 42 47 defer req.Body.Close() 43 48 resp, err := io.ReadAll(req.Body) 44 _ = json.Unmarshal([]byte(resp), & o)49 _ = json.Unmarshal([]byte(resp), &translate) 45 50 sanityCheck(err) 46 fmt.Printf("Input: %s (%s)\n",text,fromLang) 47 fmt.Printf("Output: %s (%s)\n",o.OutText,toLang) 51 // Pretty-print both the input and the output given. 52 fmt.Printf("Input: %v\n", input) 53 fmt.Printf("Output: %v\n",translate.Output) 48 54 } 49 55 func sanityCheck(err error) { -
trunk/stcli-go.1
r3 r5 1 .Dd Aftermath 5 5, 31881 .Dd Aftermath 56, 3188 2 2 .Dt STCLI-GO 1 3 3 .Os … … 10 10 .Fl f Ar from 11 11 .Fl i Ar instance 12 .Fl I Ar input 12 13 .Fl t Ar to 13 .Fl T Ar text14 14 .Sh DESCRIPTION 15 15 Self-explanatory, besides, this was made as … … 17 17 and awk for dependencies. It fully serves 18 18 as a drop-in replacement. 19 .Sh USAGE 20 .Bl -tag -width 11n -compact 21 .It -e 22 Translation engine to use 23 .It -f 24 Input language to translate from 25 .It -i 26 Instance to use 27 .It -I 28 Text to translate 29 .It -t 30 Target language to translate to 31 .El 19 32 .Sh AUTHORS 20 33 .An Aoi K. Aq Mt koizumi.aoi@kyoko-project.wer.ee … … 22 35 .An Czar of KST Aq Mt czar@kalli.st 23 36 .Pp 24 .An mutefall25 .Pp26 37 .An Shokara Kou Aq Mt kou@clearnet.fqdn 27 38 .Pp 28 39 .An Baobab Aq Mt baobab@honeypot.im 40 .Sh BUGS 41 This utility cannot translate strings 42 separated by spaces.
Note:
See TracChangeset
for help on using the changeset viewer.