deepl

package module
v0.0.0-...-8b85310 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2020 License: MIT Imports: 9 Imported by: 3

README

deepl-go

This library provides a simple API client function for Deepl.

Usage

  1. Install package
    > go get github.com/DaikiYamakawa/deepl-go
    
  2. We should register valid API key in the environment variable.
    > export DEEPL_API_KEY=xxx-xxx-xxx
    
  3. We can call deepl library in our code.
     package main
    
     import (
         "context"
         "fmt"
    
         "github.com/DaikiYamakawa/deepl-go"
     )
    
     func main() {
         cli, err := deepl.New("https://api.deepl.com", nil)
         if err != nil {
             fmt.Printf("Failed to create client:\n   %+v\n", err)
         }
         translateResponse, err := cli.TranslateSentence(context.Background(), "Hello", "EN", "JA")
         if err != nil {
             fmt.Printf("Failed to translate text:\n   %+v\n", err)
         } else {
             fmt.Printf("%+v\n", translateResponse)
         }
     }
    
    &{Translations:[{DetectedSourceLanguage:EN Text:こんにちは}]}
    

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountStatus

type AccountStatus struct {
	CharacterCount int `json:"character_count"`
	CharacterLimit int `json:"character_limit"`
}

type Client

type Client struct {
	BaseURL    *url.URL
	HTTPClient *http.Client
	Logger     *log.Logger
}

func New

func New(rawBaseURL string, logger *log.Logger) (*Client, error)

func (*Client) GetAccountStatus

func (c *Client) GetAccountStatus(ctx context.Context) (*AccountStatus, error)

func (*Client) TranslateSentence

func (c *Client) TranslateSentence(ctx context.Context, text string, sourceLang string, targetLang string) (*TranslateResponse, error)

type ErrorResponse

type ErrorResponse struct {
	ErrMessage string `json:"message"`
}

type TranslateResponse

type TranslateResponse struct {
	Translations []translation `json:"translations"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL