Categorygithub.com/cluttrdev/deepl-go
repository
0.5.0
Repository: https://github.com/cluttrdev/deepl-go.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author

# README

DeepL Go Library

This is an unofficial client library and command line interface for the DeepL API.

Getting an authentication ley

To use the DeepL Go Library, you'll need an API authentication key. To get a key, please create an account here. With a DeepL API Free account you can translate up to 500,000 characters/month for free.

Library

Installation

Using the Go tools, from inside your project:

go get github.com/cluttrdev/deepl-go

Usage

Import the package and construct a Translator.

import (
    "fmt"
    "log"
    
    deepl "github.com/cluttrdev/deepl-go/pkg/api"
)

authKey := "f63c02c5-f056-..."  // Replace with your key

translator, err := deepl.NewTranslator(authKey)
if err != nil {
    log.Fatal(err)
}

translations, err := translator.TranslateText([]string{"Hello, world!"}, "FR")
if err != nil {
    log.Fatal(err)
}

fmt.Println(translations[0].Text)  // "Bonjour, le monde !"

Command Line Interface

Installation

Your can install the deepl command line tool using a prebuilt binary, e.g. like this:

# determine latest release
VERSION=$(curl -sSL https://api.github.com/repos/cluttrdev/deepl-go/releases/latest | jq -r '.tag_name')

# download
OS=linux
ARCH=x86_64
curl -LO https://github.com/cluttrdev/deepl-go/releases/download/${VERSION}/deepl_${VERSION}_${OS}_${ARCH}.tar.gz

# extract and install (requires privileges)
BIN_DIR=/usr/local/bin
tar -zxf deepl_${VERSION}_${OS}_${ARCH}.tar.gz -C ${BIN_DIR} deepl

Alternatively, you can use the Go tools:

go install github.com/cluttrdev/deepl-go/cmd/deepl@latest

Usage

Currently, in order to use the command line interface the authentication key must be set as an environment variable.

$ export DEEPL_AUTH_KEY="f63c02c5-f056..."
$ deepl translate "Hello, world!" --target-lang FR
Bonjour, le monde !

To get an overview of the available commands, run deepl help.

Autocompletion

You can use the deepl completion command to generate autocompletion scripts for the cli.