Skip to content

LibreTranslate in golang

License

Notifications You must be signed in to change notification settings

SnakeSel/libretranslate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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())
    }
}

About

LibreTranslate in golang

Resources

License

Stars

Watchers

Forks

Languages