mirror of
https://codeberg.org/aryak/mozhi
synced 2025-06-04 00:41:07 +05:30
add the api route for translation
This commit is contained in:
@@ -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) {
|
||||
|
@@ -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
6
utils/main.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package utils
|
||||
|
||||
type List struct {
|
||||
Name string
|
||||
Id string
|
||||
}
|
14
utils/sanitize.go
Normal file
14
utils/sanitize.go
Normal 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 ""
|
||||
}
|
Reference in New Issue
Block a user