Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/piero-vic/libretranslate
Go client for the LibreTranslate API
https://github.com/piero-vic/libretranslate
Last synced: about 1 month ago
JSON representation
Go client for the LibreTranslate API
- Host: GitHub
- URL: https://github.com/piero-vic/libretranslate
- Owner: piero-vic
- License: mit
- Created: 2023-09-02T01:10:14.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-03T02:51:03.000Z (about 1 year ago)
- Last Synced: 2024-11-13T21:47:38.782Z (about 2 months ago)
- Language: Go
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `libretranslate`
A Go Wrapper for [LibreTranslate](https://libretranslate.com/).
## Installation
```bash
go get -u github.com/piero-vic/libretranslate
```## Usage
```go
package mainimport (
"fmt"
"log""github.com/piero-vic/libretranslate"
)func main() {
lt := libretranslate.NewClient("")// 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](./LICENSE) file for details.