Finally DeepL

This commit is contained in:
Arya Kiran 2023-07-23 20:00:20 +05:30
parent 9c07306f07
commit 9f7db5e347
No known key found for this signature in database
GPG key ID: 842D12BDA50DF120
6 changed files with 556 additions and 3 deletions

View file

@ -6,6 +6,4 @@
- Alternative words - Alternative words
- Dictionary - Dictionary
- Bing Translate - Bing Translate
- MyMemory
- DeepL
- ICIBA - ICIBA

View file

@ -31,7 +31,7 @@ var translateCmd = &cobra.Command{
} else if langlist == "tl" { } else if langlist == "tl" {
fmt.Println(utils.LangListDeepl(langlist)) fmt.Println(utils.LangListDeepl(langlist))
} else { } else {
fmt.Println("Not Implemented yet.") fmt.Println(utils.TranslateDeepl(dest, source, query))
} }
} else if engine == "libretranslate" { } else if engine == "libretranslate" {
if langlist == "sl" { if langlist == "sl" {

2
go.mod
View file

@ -15,7 +15,9 @@ require (
) )
require ( require (
github.com/OwO-Network/gdeeplx v0.0.1 // indirect
github.com/PuerkitoBio/goquery v1.8.1 // indirect github.com/PuerkitoBio/goquery v1.8.1 // indirect
github.com/abadojack/whatlanggo v1.0.1 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect github.com/andybalholm/brotli v1.0.5 // indirect
github.com/andybalholm/cascadia v1.3.2 // indirect github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/antchfx/htmlquery v1.3.0 // indirect github.com/antchfx/htmlquery v1.3.0 // indirect

4
go.sum
View file

@ -54,8 +54,12 @@ github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3
github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY= github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY=
github.com/Joker/jade v1.1.3/go.mod h1:T+2WLyt7VH6Lp0TRxQrUYEs64nRc83wkMQrfeIQKduM= github.com/Joker/jade v1.1.3/go.mod h1:T+2WLyt7VH6Lp0TRxQrUYEs64nRc83wkMQrfeIQKduM=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/OwO-Network/gdeeplx v0.0.1 h1:uWkXp1AiD3jAgsg9Gw5ak8TH6ZZ/RjgfFXgYA8kyE3g=
github.com/OwO-Network/gdeeplx v0.0.1/go.mod h1:xLqaj0n6E2VmiI1RXBOFy8wLoiOurvO3O6QxUvepyVo=
github.com/PuerkitoBio/goquery v1.8.1 h1:uQxhNlArOIdbrH1tr0UXwdVFgDcZDrZVdcpygAcwmWM= github.com/PuerkitoBio/goquery v1.8.1 h1:uQxhNlArOIdbrH1tr0UXwdVFgDcZDrZVdcpygAcwmWM=
github.com/PuerkitoBio/goquery v1.8.1/go.mod h1:Q8ICL1kNUJ2sXGoAhPGUdYDJvgQgHzJsnnd3H7Ho5jQ= github.com/PuerkitoBio/goquery v1.8.1/go.mod h1:Q8ICL1kNUJ2sXGoAhPGUdYDJvgQgHzJsnnd3H7Ho5jQ=
github.com/abadojack/whatlanggo v1.0.1 h1:19N6YogDnf71CTHm3Mp2qhYfkRdyvbgwWdd2EPxJRG4=
github.com/abadojack/whatlanggo v1.0.1/go.mod h1:66WiQbSbJBIlOZMsvbKe5m6pzQovxCH9B/K8tQB2uoc=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=

View file

@ -3,6 +3,7 @@ package utils
import ( import (
"github.com/gocolly/colly" "github.com/gocolly/colly"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"github.com/OwO-Network/gdeeplx"
"os" "os"
) )
@ -199,6 +200,34 @@ func TranslateYandex(to string, from string, text string) string {
answer := gjsonArr[0].String() answer := gjsonArr[0].String()
return answer return answer
} }
func TranslateDeepl(to string, from string, text string) string {
var ToValid bool
var FromValid bool
for _, v := range LangListDeepl("sl") {
if v.Id == to {
ToValid = true
}
if v.Id == from {
FromValid = true
}
if FromValid == true && ToValid == true {
break
}
}
if ToValid != true {
return "Target Language Code invalid"
}
if FromValid != true {
return "Source Language Code invalid"
}
answer, err := gdeeplx.Translate(text, from, to, 0)
if err != nil {
return "failed"
}
answer1 := answer.(map[string]interface{})
ans:= answer1["data"].(string)
return ans
}
func TranslateAll(to string, from string, query string) string { func TranslateAll(to string, from string, query string) string {
reverso := TranslateReverso(to, from, query) reverso := TranslateReverso(to, from, query)
google := TranslateGoogle(to, from, query) google := TranslateGoogle(to, from, query)

520
utils/langlist-bing.go Normal file
View file

@ -0,0 +1,520 @@
package utils
func LangListBing(listType string) []List {
// Converted json of https://github.com/plainheart/bing-translate-api/blob/master/src/lang.json to this format
var ListData = []List{
List{
Id: "af",
Name: "Afrikaans",
},
List{
Id: "sq",
Name: "Albanian",
},
List{
Id: "am",
Name: "Amharic",
},
List{
Id: "ar",
Name: "Arabic",
},
List{
Id: "hy",
Name: "Armenian",
},
List{
Id: "as",
Name: "Assamese",
},
List{
Id: "az",
Name: "Azerbaijani",
},
List{
Id: "bn",
Name: "Bangla",
},
List{
Id: "ba",
Name: "Bashkir",
},
List{
Id: "eu",
Name: "Basque",
},
List{
Id: "bs",
Name: "Bosnian",
},
List{
Id: "bg",
Name: "Bulgarian",
},
List{
Id: "yue",
Name: "Cantonese (Traditional)",
},
List{
Id: "ca",
Name: "Catalan",
},
List{
Id: "lzh",
Name: "Chinese (Literary)",
},
List{
Id: "zh-Hans",
Name: "Chinese Simplified",
},
List{
Id: "zh-Hant",
Name: "Chinese Traditional",
},
List{
Id: "hr",
Name: "Croatian",
},
List{
Id: "cs",
Name: "Czech",
},
List{
Id: "da",
Name: "Danish",
},
List{
Id: "prs",
Name: "Dari",
},
List{
Id: "dv",
Name: "Divehi",
},
List{
Id: "nl",
Name: "Dutch",
},
List{
Id: "en",
Name: "English",
},
List{
Id: "et",
Name: "Estonian",
},
List{
Id: "fo",
Name: "Faroese",
},
List{
Id: "fj",
Name: "Fijian",
},
List{
Id: "fil",
Name: "Filipino",
},
List{
Id: "fi",
Name: "Finnish",
},
List{
Id: "fr",
Name: "French",
},
List{
Id: "fr-CA",
Name: "French (Canada)",
},
List{
Id: "gl",
Name: "Galician",
},
List{
Id: "lug",
Name: "Ganda",
},
List{
Id: "ka",
Name: "Georgian",
},
List{
Id: "de",
Name: "German",
},
List{
Id: "el",
Name: "Greek",
},
List{
Id: "gu",
Name: "Gujarati",
},
List{
Id: "ht",
Name: "Haitian Creole",
},
List{
Id: "ha",
Name: "Hausa",
},
List{
Id: "he",
Name: "Hebrew",
},
List{
Id: "hi",
Name: "Hindi",
},
List{
Id: "mww",
Name: "Hmong Daw",
},
List{
Id: "hu",
Name: "Hungarian",
},
List{
Id: "is",
Name: "Icelandic",
},
List{
Id: "ig",
Name: "Igbo",
},
List{
Id: "id",
Name: "Indonesian",
},
List{
Id: "ikt",
Name: "Inuinnaqtun",
},
List{
Id: "iu",
Name: "Inuktitut",
},
List{
Id: "iu-Latn",
Name: "Inuktitut (Latin)",
},
List{
Id: "ga",
Name: "Irish",
},
List{
Id: "it",
Name: "Italian",
},
List{
Id: "ja",
Name: "Japanese",
},
List{
Id: "kn",
Name: "Kannada",
},
List{
Id: "kk",
Name: "Kazakh",
},
List{
Id: "km",
Name: "Khmer",
},
List{
Id: "rw",
Name: "Kinyarwanda",
},
List{
Id: "tlh-Latn",
Name: "Klingon (Latin)",
},
List{
Id: "gom",
Name: "Konkani",
},
List{
Id: "ko",
Name: "Korean",
},
List{
Id: "ku",
Name: "Kurdish (Central)",
},
List{
Id: "kmr",
Name: "Kurdish (Northern)",
},
List{
Id: "ky",
Name: "Kyrgyz",
},
List{
Id: "lo",
Name: "Lao",
},
List{
Id: "lv",
Name: "Latvian",
},
List{
Id: "ln",
Name: "Lingala",
},
List{
Id: "lt",
Name: "Lithuanian",
},
List{
Id: "dsb",
Name: "Lower Sorbian",
},
List{
Id: "mk",
Name: "Macedonian",
},
List{
Id: "mai",
Name: "Maithili",
},
List{
Id: "mg",
Name: "Malagasy",
},
List{
Id: "ms",
Name: "Malay",
},
List{
Id: "ml",
Name: "Malayalam",
},
List{
Id: "mt",
Name: "Maltese",
},
List{
Id: "mr",
Name: "Marathi",
},
List{
Id: "mn-Cyrl",
Name: "Mongolian (Cyrillic)",
},
List{
Id: "mn-Mong",
Name: "Mongolian (Traditional)",
},
List{
Id: "my",
Name: "Myanmar (Burmese)",
},
List{
Id: "mi",
Name: "Māori",
},
List{
Id: "ne",
Name: "Nepali",
},
List{
Id: "nb",
Name: "Norwegian",
},
List{
Id: "nya",
Name: "Nyanja",
},
List{
Id: "or",
Name: "Odia",
},
List{
Id: "ps",
Name: "Pashto",
},
List{
Id: "fa",
Name: "Persian",
},
List{
Id: "pl",
Name: "Polish",
},
List{
Id: "pt",
Name: "Portuguese (Brazil)",
},
List{
Id: "pt-PT",
Name: "Portuguese (Portugal)",
},
List{
Id: "pa",
Name: "Punjabi",
},
List{
Id: "otq",
Name: "Querétaro Otomi",
},
List{
Id: "ro",
Name: "Romanian",
},
List{
Id: "run",
Name: "Rundi",
},
List{
Id: "ru",
Name: "Russian",
},
List{
Id: "sm",
Name: "Samoan",
},
List{
Id: "sr-Cyrl",
Name: "Serbian (Cyrillic)",
},
List{
Id: "sr-Latn",
Name: "Serbian (Latin)",
},
List{
Id: "st",
Name: "Sesotho",
},
List{
Id: "nso",
Name: "Sesotho sa Leboa",
},
List{
Id: "tn",
Name: "Setswana",
},
List{
Id: "sn",
Name: "Shona",
},
List{
Id: "sd",
Name: "Sindhi",
},
List{
Id: "si",
Name: "Sinhala",
},
List{
Id: "sk",
Name: "Slovak",
},
List{
Id: "sl",
Name: "Slovenian",
},
List{
Id: "so",
Name: "Somali",
},
List{
Id: "es",
Name: "Spanish",
},
List{
Id: "sw",
Name: "Swahili",
},
List{
Id: "sv",
Name: "Swedish",
},
List{
Id: "ty",
Name: "Tahitian",
},
List{
Id: "ta",
Name: "Tamil",
},
List{
Id: "tt",
Name: "Tatar",
},
List{
Id: "te",
Name: "Telugu",
},
List{
Id: "th",
Name: "Thai",
},
List{
Id: "bo",
Name: "Tibetan",
},
List{
Id: "ti",
Name: "Tigrinya",
},
List{
Id: "to",
Name: "Tongan",
},
List{
Id: "tr",
Name: "Turkish",
},
List{
Id: "tk",
Name: "Turkmen",
},
List{
Id: "uk",
Name: "Ukrainian",
},
List{
Id: "hsb",
Name: "Upper Sorbian",
},
List{
Id: "ur",
Name: "Urdu",
},
List{
Id: "ug",
Name: "Uyghur",
},
List{
Id: "uz",
Name: "Uzbek (Latin)",
},
List{
Id: "vi",
Name: "Vietnamese",
},
List{
Id: "cy",
Name: "Welsh",
},
List{
Id: "xh",
Name: "Xhosa",
},
List{
Id: "yo",
Name: "Yoruba",
},
List{
Id: "yua",
Name: "Yucatec Maya",
},
List{
Id: "zu",
Name: "Zulu",
},
}
return ListData
}