add the api route for translation

This commit is contained in:
2023-08-15 21:41:02 +05:30
parent 977e3dff2e
commit f7ec6b556d
6 changed files with 62 additions and 31 deletions

View File

@@ -11,8 +11,10 @@ import (
)
type LangOut struct {
OutputText string
AutoDetect string
OutputText string `json:"translated-text"`
AutoDetect string `json:"detected"`
SourceLang string `json:"source_language"`
TargetLang string `json:"target_language"`
}
func TranslateGoogle(to string, from string, text string) (LangOut, error) {

View File

@@ -1,10 +1,5 @@
package utils
type List struct {
Name string
Id string
}
func LangListReverso(listType string) []List {
// IDs got from original simplytranslate-web and trial and error. Usually first three letters of language.
var ListData = []List{

6
utils/main.go Normal file
View File

@@ -0,0 +1,6 @@
package utils
type List struct {
Name string
Id string
}

14
utils/sanitize.go Normal file
View File

@@ -0,0 +1,14 @@
package utils
import "regexp"
func Sanitize(str string, strip string) string {
nonAlphanumericRegex := regexp.MustCompile(`[^a-zA-Z]+`)
nonAlphaRegex := regexp.MustCompile(`[^a-zA-Z0-9]+`)
if strip == "alpha" {
return nonAlphaRegex.ReplaceAllString(str, "")
} else if strip == "alphanumeric" {
return nonAlphanumericRegex.ReplaceAllString(str, "")
}
return ""
}