mirror of
https://codeberg.org/aryak/mozhi
synced 2024-12-22 16:59:49 +05:30
gofmt
This commit is contained in:
parent
fa3612fbdf
commit
bfd34a06f8
@ -1,13 +1,13 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gocolly/colly"
|
|
||||||
"strings"
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/google/go-querystring/query"
|
|
||||||
"github.com/OwO-Network/gdeeplx"
|
|
||||||
"os"
|
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/OwO-Network/gdeeplx"
|
||||||
|
"github.com/gocolly/colly"
|
||||||
|
"github.com/google/go-querystring/query"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LangOut struct {
|
type LangOut struct {
|
||||||
@ -26,7 +26,7 @@ func TranslateGoogle(to string, from string, text string) (LangOut, error) {
|
|||||||
var FromValid bool
|
var FromValid bool
|
||||||
for _, v := range LangListGoogle("sl") {
|
for _, v := range LangListGoogle("sl") {
|
||||||
if v.Id == to {
|
if v.Id == to {
|
||||||
ToValid = true
|
ToValid = true
|
||||||
}
|
}
|
||||||
if v.Id == from {
|
if v.Id == from {
|
||||||
FromValid = true
|
FromValid = true
|
||||||
@ -70,7 +70,7 @@ func TranslateReverso(to string, from string, query string) (LangOut, error) {
|
|||||||
var FromValid bool
|
var FromValid bool
|
||||||
for _, v := range LangListReverso("sl") {
|
for _, v := range LangListReverso("sl") {
|
||||||
if v.Id == to {
|
if v.Id == to {
|
||||||
ToValid = true
|
ToValid = true
|
||||||
}
|
}
|
||||||
if v.Id == from {
|
if v.Id == from {
|
||||||
FromValid = true
|
FromValid = true
|
||||||
@ -97,7 +97,7 @@ func TranslateLibreTranslate(to string, from string, query string) (LangOut, err
|
|||||||
var FromValid bool
|
var FromValid bool
|
||||||
for _, v := range LangListLibreTranslate("sl") {
|
for _, v := range LangListLibreTranslate("sl") {
|
||||||
if v.Id == to {
|
if v.Id == to {
|
||||||
ToValid = true
|
ToValid = true
|
||||||
}
|
}
|
||||||
if v.Id == from {
|
if v.Id == from {
|
||||||
FromValid = true
|
FromValid = true
|
||||||
@ -125,7 +125,7 @@ func TranslateWatson(to string, from string, query string) (LangOut, error) {
|
|||||||
var FromValid bool
|
var FromValid bool
|
||||||
for _, v := range LangListWatson("sl") {
|
for _, v := range LangListWatson("sl") {
|
||||||
if v.Id == to {
|
if v.Id == to {
|
||||||
ToValid = true
|
ToValid = true
|
||||||
}
|
}
|
||||||
if v.Id == from {
|
if v.Id == from {
|
||||||
FromValid = true
|
FromValid = true
|
||||||
@ -152,7 +152,7 @@ func TranslateMyMemory(to string, from string, text string) (LangOut, error) {
|
|||||||
var FromValid bool
|
var FromValid bool
|
||||||
for _, v := range LangListMyMemory("sl") {
|
for _, v := range LangListMyMemory("sl") {
|
||||||
if v.Id == to {
|
if v.Id == to {
|
||||||
ToValid = true
|
ToValid = true
|
||||||
}
|
}
|
||||||
if v.Id == from {
|
if v.Id == from {
|
||||||
FromValid = true
|
FromValid = true
|
||||||
@ -171,7 +171,7 @@ func TranslateMyMemory(to string, from string, text string) (LangOut, error) {
|
|||||||
Translate string `url:"langpair"`
|
Translate string `url:"langpair"`
|
||||||
Text string `url:"q"`
|
Text string `url:"q"`
|
||||||
}
|
}
|
||||||
opt := Options{ from+"|"+to, text }
|
opt := Options{from + "|" + to, text}
|
||||||
v, _ := query.Values(opt)
|
v, _ := query.Values(opt)
|
||||||
myMemoryOut := GetRequest("https://api.mymemory.translated.net/get?" + v.Encode())
|
myMemoryOut := GetRequest("https://api.mymemory.translated.net/get?" + v.Encode())
|
||||||
gjsonArr := myMemoryOut.Get("responseData.translatedText").Array()
|
gjsonArr := myMemoryOut.Get("responseData.translatedText").Array()
|
||||||
@ -184,7 +184,7 @@ func TranslateYandex(to string, from string, text string) (LangOut, error) {
|
|||||||
var FromValid bool
|
var FromValid bool
|
||||||
for _, v := range LangListYandex("sl") {
|
for _, v := range LangListYandex("sl") {
|
||||||
if v.Id == to {
|
if v.Id == to {
|
||||||
ToValid = true
|
ToValid = true
|
||||||
}
|
}
|
||||||
if v.Id == from {
|
if v.Id == from {
|
||||||
FromValid = true
|
FromValid = true
|
||||||
@ -205,12 +205,12 @@ func TranslateYandex(to string, from string, text string) (LangOut, error) {
|
|||||||
Srv string `url:"srv"`
|
Srv string `url:"srv"`
|
||||||
Id string `url:"sid"`
|
Id string `url:"sid"`
|
||||||
}
|
}
|
||||||
uuidWithHyphen := uuid.New()
|
uuidWithHyphen := uuid.New()
|
||||||
uuid := strings.Replace(uuidWithHyphen.String(), "-", "", -1)
|
uuid := strings.Replace(uuidWithHyphen.String(), "-", "", -1)
|
||||||
opt := Options{from + "-" + to, text, "android", uuid+"-0-0"}
|
opt := Options{from + "-" + to, text, "android", uuid + "-0-0"}
|
||||||
v, _ := query.Values(opt)
|
v, _ := query.Values(opt)
|
||||||
|
|
||||||
yandexOut := PostRequest("https://translate.yandex.net/api/v1/tr.json/translate?" + v.Encode(), []byte(""))
|
yandexOut := PostRequest("https://translate.yandex.net/api/v1/tr.json/translate?"+v.Encode(), []byte(""))
|
||||||
gjsonArr := yandexOut.Get("text.0").Array()
|
gjsonArr := yandexOut.Get("text.0").Array()
|
||||||
var langout LangOut
|
var langout LangOut
|
||||||
langout.OutputText = gjsonArr[0].String()
|
langout.OutputText = gjsonArr[0].String()
|
||||||
@ -221,7 +221,7 @@ func TranslateDeepl(to string, from string, text string) (LangOut, error) {
|
|||||||
var FromValid bool
|
var FromValid bool
|
||||||
for _, v := range LangListDeepl("sl") {
|
for _, v := range LangListDeepl("sl") {
|
||||||
if v.Id == to {
|
if v.Id == to {
|
||||||
ToValid = true
|
ToValid = true
|
||||||
}
|
}
|
||||||
if v.Id == from {
|
if v.Id == from {
|
||||||
FromValid = true
|
FromValid = true
|
||||||
@ -241,7 +241,7 @@ func TranslateDeepl(to string, from string, text string) (LangOut, error) {
|
|||||||
return LangOut{}, errors.New("failed")
|
return LangOut{}, errors.New("failed")
|
||||||
}
|
}
|
||||||
answer1 := answer.(map[string]interface{})
|
answer1 := answer.(map[string]interface{})
|
||||||
ans:= answer1["data"].(string)
|
ans := answer1["data"].(string)
|
||||||
var langout LangOut
|
var langout LangOut
|
||||||
langout.OutputText = ans
|
langout.OutputText = ans
|
||||||
return langout, nil
|
return langout, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user