🐛 Try to fix the language detect issue
This commit is contained in:
parent
27994733dd
commit
7ae1f8021b
@ -6,12 +6,20 @@ import (
|
|||||||
"github.com/pemistahl/lingua-go"
|
"github.com/pemistahl/lingua-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DetectLanguage(content string) string {
|
var detector lingua.LanguageDetector
|
||||||
return "unknown"
|
|
||||||
|
|
||||||
detector := lingua.NewLanguageDetectorBuilder().
|
func CreateLanguageDetector() lingua.LanguageDetector {
|
||||||
FromLanguages(lingua.AllLanguages()...).
|
return lingua.NewLanguageDetectorBuilder().
|
||||||
|
FromAllLanguages().
|
||||||
|
WithLowAccuracyMode().
|
||||||
Build()
|
Build()
|
||||||
|
}
|
||||||
|
|
||||||
|
func DetectLanguage(content string) string {
|
||||||
|
if detector == nil {
|
||||||
|
detector = CreateLanguageDetector()
|
||||||
|
}
|
||||||
|
|
||||||
if lang, ok := detector.DetectLanguageOf(content); ok {
|
if lang, ok := detector.DetectLanguageOf(content); ok {
|
||||||
return strings.ToLower(lang.String())
|
return strings.ToLower(lang.String())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user