Skip to content

piero-vic/libretranslate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libretranslate

A Go Wrapper for LibreTranslate.

Installation

go get -u github.com/piero-vic/libretranslate

Usage

package main

import (
	"fmt"
	"log"

	"github.com/piero-vic/libretranslate"
)

func main() {
	lt := libretranslate.NewClient("<your_api_token>")

	// Example 1: Detect Language
	detectedLanguages, err := lt.Detect("Hello, world!")
	if err != nil {
		log.Fatalf("Detection failed: %v", err)
	}

	fmt.Println("Detected languages for 'Hello, world!':")
	for _, detectedLang := range detectedLanguages {
		fmt.Printf("Language: %s, Confidence: %.2f\n", detectedLang.Language, detectedLang.Confidence)
	}

	// Example 2: Translate Text
	sourceLanguage := "en"
	targetLanguage := "fr"
	textToTranslate := "Hello, world!"

	translatedText, err := lt.Translate(textToTranslate, sourceLanguage, targetLanguage)
	if err != nil {
		log.Fatalf("Translation failed: %v", err)
	}

	fmt.Printf("Translation from '%s' to '%s':\n", sourceLanguage, targetLanguage)
	fmt.Printf("Original Text: %s\n", textToTranslate)
	fmt.Printf("Translated Text: %s\n", translatedText)
}

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Go client for the LibreTranslate API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages