This is an unofficial Go SDK for using the DeepL API.
go get github.com/michimani/deepl-sdk-go
package main
import (
"context"
"fmt"
"os"
"github.com/michimani/deepl-sdk-go"
"github.com/michimani/deepl-sdk-go/params"
"github.com/michimani/deepl-sdk-go/types"
)
func main() {
client, err := deepl.NewClient()
if err != nil {
fmt.Println(err)
return
}
text := []string{
"こんにちは",
"これはサンプルテキストです。",
}
params := ¶ms.TranslateTextParams{
TargetLang: types.TargetLangEN,
Text: text,
}
res, errRes, err := c.TranslateText(context.TODO(), params)
if err != nil {
fmt.Println(err)
}
if errRes != nil {
fmt.Println("ErrorResponse", errRes.Message)
}
for i := range res.Translations {
fmt.Printf("%s -> %s\n", text[i], res.Translations[i].Text)
}
}
$ DEEPL_API_AUTHN_KEY="your-authn-key" DEEPL_API_PLAN="free" go run main.go
こんにちは -> hello
これはサンプルテキストです。 -> This is a sample text.