Language's post

This commit is contained in:
2024-07-13 23:16:40 +08:00
parent ad3257dabf
commit c67a38f4bb
10 changed files with 58 additions and 19 deletions

View File

@@ -0,0 +1,18 @@
package services
import (
"github.com/pemistahl/lingua-go"
"strings"
)
func DetectLanguage(content *string) string {
if content != nil {
detector := lingua.NewLanguageDetectorBuilder().
FromLanguages(lingua.AllLanguages()...).
Build()
if lang, ok := detector.DetectLanguageOf(*content); ok {
return strings.ToLower(lang.String())
}
}
return "unknown"
}