Interactive/pkg/internal/services/languages.go

20 lines
363 B
Go
Raw Normal View History

2024-07-13 15:16:40 +00:00
package services
import (
"strings"
"github.com/pemistahl/lingua-go"
2024-07-13 15:16:40 +00:00
)
func DetectLanguage(content string) string {
return "unknown"
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"
}