Skip to content

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

License

Notifications You must be signed in to change notification settings

michimani/deepl-sdk-go

Repository files navigation

deepl-sdk-go

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

Usage

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

Sample

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)
	}
}
$ DEEPL_API_AUTHN_KEY="your-authn-key" DEEPL_API_PLAN="free" go run main.go

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages