Changeset 10 in code
- Timestamp:
- Mar 13, 2023, 11:17:03 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/main.go
r9 r10 1 // $TheSupernovaDuo: stcli,v 1. 3.1 2023/02/11 07:54:25 akoizumi Exp1 // $TheSupernovaDuo: stcli,v 1.4.0 2023/03/13 08:14:55 akoizumi Exp 2 2 // Command line client for SimplyTranslate, a privacy friendly frontend to other translation engines 3 3 package main … … 11 11 "net/url" 12 12 ) 13 13 14 var ( 14 15 engine string 15 from string16 16 instance string 17 17 input string 18 to string 18 source string 19 target string 19 20 ) 20 21 type Translate struct { … … 22 23 } 23 24 func init() { 24 flag.StringVar(&engine, "e", "google", "Translation engine to use (default: google)")25 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")26 flag.StringVar(&instance, "i", "https:// simplytranslate.org/api/translate/", "Instance to use (default: https://simplytranslate.org/api/translate/)")25 flag.StringVar(&engine, "e", "google", "Translation engine to use") 26 flag.StringVar(&source, "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://translate.bus-hit.me", "Instance to use)") 27 28 flag.StringVar(&input, "I", "", "Enter the text to be translated") 28 flag.StringVar(&t o, "t", "en", "Set the language to translate to (default: en)")29 flag.StringVar(&target, "t", "en", "Set the language to translate to") 29 30 } 30 31 func main() { 31 32 // Begin flag parsing 32 33 flag.Parse() 33 // Check if any of those two variables is empty. 34 // It actually needs the two to have content. 34 // Check if there's any input, otherwise bail out. 35 35 if len(input) == 0 { 36 36 log.Fatal("Missing input.") … … 39 39 var translate Translate 40 40 // Build the full URL to query 41 var encinput = url.PathEscape(input) 42 var queryURL = instance + "?engine=" + engine + "&from=" + from + "&to=" + to + "&text=" + encinput 41 var encInput = url.PathEscape(input) 42 var apiEndpoint = "/api/translate" 43 var queryURL = instance + apiEndpoint + "?engine=" + engine + "&from=" + source + "&to=" + target + "&text=" + encInput 43 44 // Begin the request and process the response 44 45 resp, err := http.Get(queryURL)
Note:
See TracChangeset
for help on using the changeset viewer.