go-deepl is a simple Go library for DeepL API client.
Note: It is a fork from deepl-go by shopper29 with some modifications. Such as security updates, replacing deprecated modules, code coverage, etc.
go get github.com/KEINOS/go-deepl
import "github.com/KEINOS/go-deepl/deepl"
- You need an account of DeepL API Free or Pro.
- The environment variable
DEEPL_API_KEY
and a valid API key ("Authentication Key for DeepL API" from your account settings) must be set.
package main
import (
"context"
"fmt"
"github.com/KEINOS/go-deepl/deepl"
)
func main() {
// Create a client for free account of DeepL API (choices: deepl.APIFree,
// deepl.APIPro, deepl.APICustom). The second arg is the logger. If nil,
// the default logger is used. Which logs to stderr.
cli, err := deepl.New(deepl.APIFree, nil)
if err != nil {
log.Fatal(err)
}
translateResponse, err := cli.TranslateSentence(
context.Background(),
"Hello", // Phrase to translate
"EN", // from English
"JA", // to Japanese
)
if err != nil {
log.Fatal(err)
} else {
fmt.Printf("%+v\n", translateResponse)
}
// Output:
// &{Translations:[{DetectedSourceLanguage:EN Text:こんにちは}]}
}
- See more examples @ GoDocs
- MIT License. Copyright (c) 2023 shopper29, KEINOS and the go-deepl contributors.