Detect language in controller layer

This commit is contained in:
2024-07-22 01:46:38 +08:00
parent 96b36c1db4
commit d4dfa810d1
4 changed files with 14 additions and 8 deletions

View File

@@ -5,14 +5,12 @@ import (
"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())
}
func DetectLanguage(content string) string {
detector := lingua.NewLanguageDetectorBuilder().
FromLanguages(lingua.AllLanguages()...).
Build()
if lang, ok := detector.DetectLanguageOf(content); ok {
return strings.ToLower(lang.String())
}
return "unknown"
}