From a1c229e1077d565e072e4f5626d2f12ee1283ff6 Mon Sep 17 00:00:00 2001 From: Arya Kiran Date: Sun, 25 Jun 2023 00:11:11 +0530 Subject: [PATCH] gofmt --- cmd/translate.go | 2 +- utils/engines.go | 127 ++++++++++++++++++++++---------------------- utils/getrequest.go | 2 +- 3 files changed, 66 insertions(+), 65 deletions(-) diff --git a/cmd/translate.go b/cmd/translate.go index 3b8d399..a45fd98 100644 --- a/cmd/translate.go +++ b/cmd/translate.go @@ -1,9 +1,9 @@ package cmd import ( - "github.com/spf13/cobra" "codeberg.org/aryak/simplytranslate/utils" "fmt" + "github.com/spf13/cobra" ) var engine string diff --git a/utils/engines.go b/utils/engines.go index dce71db..6895ad0 100644 --- a/utils/engines.go +++ b/utils/engines.go @@ -1,11 +1,12 @@ package utils import ( + "fmt" "github.com/gocolly/colly" "os" - "fmt" "strings" ) + type List struct { Name string Id string @@ -26,7 +27,7 @@ func TranslateGoogle(to string, from string, query string) string { return answer } func TranslateReverso(to string, from string, query string) string { - json := []byte(`{ "format": "text", "from": "`+from+`", "to": "`+to+`", "input":"`+query+`", "options": {"sentenceSplitter": false, "origin":"translation.web", contextResults: false, languageDetection: true} }`) + json := []byte(`{ "format": "text", "from": "` + from + `", "to": "` + to + `", "input":"` + query + `", "options": {"sentenceSplitter": false, "origin":"translation.web", contextResults: false, languageDetection: true} }`) reversoOut := GetRequest("https://api.reverso.net/translate/v1/translation", json) gjsonArr := reversoOut.Get("translation").Array() answer := gjsonArr[0].String() @@ -35,9 +36,9 @@ func TranslateReverso(to string, from string, query string) string { func TranslateAll(to string, from string, query string) string { reverso := TranslateReverso(to, from, query) google := TranslateGoogle(to, from, query) - fmt.Println("Google: "+google) - fmt.Println("Reverso: "+reverso) - return "Google: "+google + "\nReverso: "+reverso + fmt.Println("Google: " + google) + fmt.Println("Reverso: " + reverso) + return "Google: " + google + "\nReverso: " + reverso } func LangListGoogle(listType string) []List { UserAgent, ok := os.LookupEnv("SIMPLYTRANSLATE_USER_AGENT") @@ -51,122 +52,122 @@ func LangListGoogle(listType string) []List { var ListInfo List ListInfo.Name = el.ChildText("a") if listType == "tl" { - ListInfo.Id = strings.TrimPrefix(strings.TrimSuffix(el.ChildAttr("a", "href"), "&hl=en-US"), "./m?sl=en&tl=") - } else { - ListInfo.Id = strings.TrimPrefix(strings.TrimSuffix(el.ChildAttr("a", "href"), "&tl=en&hl=en-US"), "./m?sl=") - } + ListInfo.Id = strings.TrimPrefix(strings.TrimSuffix(el.ChildAttr("a", "href"), "&hl=en-US"), "./m?sl=en&tl=") + } else { + ListInfo.Id = strings.TrimPrefix(strings.TrimSuffix(el.ChildAttr("a", "href"), "&tl=en&hl=en-US"), "./m?sl=") + } ListData = append(ListData, ListInfo) }) }) - url := "https://translate.google.com/m?sl=en&tl=en&hl=en-US&mui="+listType + url := "https://translate.google.com/m?sl=en&tl=en&hl=en-US&mui=" + listType sc.Visit(url) return ListData } func LangListReverso(listType string) []List { // IDs got from original simplytranslate-web and trial and error. Usually first three letters of language. - var ListData = []List { - List { - Id: "ara", + var ListData = []List{ + List{ + Id: "ara", Name: "Arabic", }, - List { - Id: "chi", + List{ + Id: "chi", Name: "Chinese (Simplified)", }, - List { - Id: "cze", + List{ + Id: "cze", Name: "Czech", }, - List { - Id: "dan", + List{ + Id: "dan", Name: "Danish", }, - List { - Id: "dut", + List{ + Id: "dut", Name: "Dutch", }, - List { - Id: "eng", + List{ + Id: "eng", Name: "English", }, - List { - Id: "fra", + List{ + Id: "fra", Name: "French", }, - List { - Id: "ger", + List{ + Id: "ger", Name: "German", }, - List { - Id: "gre", + List{ + Id: "gre", Name: "Greek", }, - List { - Id: "Hebrew", + List{ + Id: "Hebrew", Name: "heb", }, - List { - Id: "hin", + List{ + Id: "hin", Name: "Hindi", }, - List { - Id: "hun", + List{ + Id: "hun", Name: "Hungarian", }, - List { - Id: "ita", + List{ + Id: "ita", Name: "Italian", }, - List { - Id: "jpn", + List{ + Id: "jpn", Name: "Japanese", }, - List { - Id: "kor", + List{ + Id: "kor", Name: "Korean", }, - List { - Id: "per", + List{ + Id: "per", Name: "Persian", }, - List { - Id: "pol", + List{ + Id: "pol", Name: "Polish", }, - List { - Id: "por", + List{ + Id: "por", Name: "Portugese", }, - List { - Id: "rum", + List{ + Id: "rum", Name: "Romanian", }, - List { - Id: "rus", + List{ + Id: "rus", Name: "Russian", }, - List { - Id: "slo", + List{ + Id: "slo", Name: "Slovakian", }, - List { - Id: "spa", + List{ + Id: "spa", Name: "Spanish", }, - List { - Id: "swe", + List{ + Id: "swe", Name: "Swedish", }, - List { - Id: "tha", + List{ + Id: "tha", Name: "Thai", }, - List { - Id: "tur", + List{ + Id: "tur", Name: "Turkish", }, - List { - Id: "ukr", + List{ + Id: "ukr", Name: "Ukrainian", }, } diff --git a/utils/getrequest.go b/utils/getrequest.go index 337e9bb..3a710eb 100644 --- a/utils/getrequest.go +++ b/utils/getrequest.go @@ -1,8 +1,8 @@ package utils import ( - "github.com/tidwall/gjson" "bytes" + "github.com/tidwall/gjson" "io" "net/http" "os"