feat: Automatically detect the source lang

This commit is contained in:
cijiugechu
2023-03-02 14:36:41 +08:00
parent c870ce0dc7
commit 4a79f9ffad
3 changed files with 23 additions and 5 deletions
+5 -3
View File
@@ -11,6 +11,7 @@ import (
"strings"
"time"
"github.com/abadojack/whatlanggo"
"github.com/gin-gonic/gin"
"github.com/tidwall/gjson"
)
@@ -121,14 +122,15 @@ func main() {
sourceLang := reqj.SourceLang
targetLang := reqj.TargetLang
translateText := reqj.TransText
if sourceLang == "" {
sourceLang = "ZH"
lang := whatlanggo.DetectLang(translateText)
deepLLang := strings.ToUpper(lang.Iso6391())
sourceLang = deepLLang
}
if targetLang == "" {
targetLang = "EN"
}
translateText := reqj.TransText
// fmt.Printf("%v", translateText)
if translateText == "" {
c.JSON(http.StatusNotFound, gin.H{
"code": http.StatusNotFound,