Awesome
LibreTranslate in golang
LibreTranslate is an Open Source Machine Translation
API Docs | Self-Hosted
Install:
go get -u github.com/snakesel/libretranslate
Example usage:
package main
import (
"fmt"
tr "github.com/snakesel/libretranslate"
)
func main() {
translate := tr.New(tr.Config{
Url: "https://libretranslate.com",
Key: "XXX",
})
// you can use "auto" for source language
// so, translator will detect language
trtext, err := translate.Translate("Hello, World!", "auto", "ru")
if err == nil {
fmt.Println(trtext)
} else {
fmt.Println(err.Error())
}
// Detect the language of the text
conf, lang, err := translate.Detect("Nächster Stil")
if err == nil {
fmt.Printf("%s (%f)\n", lang, conf)
} else {
fmt.Println(err.Error())
}
}