Interactive/pkg/internal/services/languages.go

17 lines
343 B
Go
Raw Normal View History

2024-07-13 15:16:40 +00:00
package services
import (
"github.com/pemistahl/lingua-go"
"strings"
)
func DetectLanguage(content string) string {
detector := lingua.NewLanguageDetectorBuilder().
FromLanguages(lingua.AllLanguages()...).
Build()
if lang, ok := detector.DetectLanguageOf(content); ok {
return strings.ToLower(lang.String())
2024-07-13 15:16:40 +00:00
}
return "unknown"
}