How to Implement Language Detection in Go

Go requires third-party libraries like whatlanggo to detect the language of text strings as it lacks native support.

Go does not have a built-in language detection feature; you must use a third-party library like github.com/cloudfoundry-incubator/go-langdetect or github.com/abadojack/whatlanggo to identify the language of a text string. Install the library and pass your text to its detection function to receive the identified language code.

package main

import (
	"fmt"
	"github.com/abadojack/whatlanggo"
)

func main() {
	text := "Hello world"
	lang := whatlanggo.Detect(text)
	fmt.Println(lang.Code) // Output: en
}