An open API service indexing awesome lists of open source software.

https://github.com/michimani/deepl-sdk-go

This is a an unofficial Go SDK for using the DeepL API.
https://github.com/michimani/deepl-sdk-go

deepl golang sdk

Last synced: about 1 month ago
JSON representation

This is a an unofficial Go SDK for using the DeepL API.

Awesome Lists containing this project

README

        

deepl-sdk-go
===

This is an unofficial Go SDK for using the DeepL API.

# Usage

```bash
go get github.com/michimani/deepl-sdk-go
```

# Sample

```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 := &params.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)
}
}
```

```bash
$ DEEPL_API_AUTHN_KEY="your-authn-key" DEEPL_API_PLAN="free" go run main.go

こんにちは -> hello
これはサンプルテキストです。 -> This is a sample text.
```