getlang package - github.com/rylans/getlang - Go Packages

Package getlang provides fast natural language detection for various languages

getlang compares input text to a characteristic profile of each supported language and returns the language that best matches the input text

This section is empty.

This section is empty.

This section is empty.

Info is the language detection result

FromReader detects the language from an io.Reader

This function will read all bytes until an EOF is reached

FromString detects the language from the given string

Confidence returns a measure of reliability for the language classification

The output value is in the range [0, 1.0] inclusive

package main

import (
	"fmt"
	"github.com/rylans/getlang"
)

func main() {
	short := getlang.FromString("short text")
	long := getlang.FromString("this sentence is a bit longer")
	fmt.Println(long.Confidence() > short.Confidence())
}
Output:

true
func (info Info) LanguageCode() string

LanguageCode returns the ISO 639-1 code for the detected language

package main

import (
	"fmt"
	"github.com/rylans/getlang"
)

func main() {
	fmt.Println(getlang.FromString("статей на русском").LanguageCode())
}
Output:

ru
func (info Info) LanguageName() string

LanguageName returns the English name of the detected language

package main

import (
	"fmt"
	"github.com/rylans/getlang"
)

func main() {
	fmt.Println(getlang.FromString("何ですか?").LanguageName())
}
Output:

Japanese

SelfName returns the name of the language in the language itself

package main

import (
	"fmt"
	"github.com/rylans/getlang"
)

func main() {
	fmt.Println(getlang.FromString("何ですか?").SelfName())
}
Output:

日本語

Tag returns the language.Tag of the detected language

package main

import (
	"fmt"
	"github.com/rylans/getlang"
)

func main() {
	fmt.Println(getlang.FromString("何ですか?").Tag().IsRoot())
}
Output:

false