Giter Site home page Giter Site logo

godeepl's Introduction

GoDeepl - A Deepl API wrapper

This is a Go wrapper around the (mostly undocumented) JSON RPC API of the online translation service Deepl.

How to use it

Authentication

Create a client specifying the preferred endpoint to be used. You can chose between the public API (which is strongly ratelimited) and the pro API which needs authentication.

Public API

// Defaultly, when no options are passed, 
// EndpointPublic is used as API endpoint.
c := godeepl.New()

Pro API

c := godeepl.New(godeepl.ClientOptions{
    // Select the Pro API endpoint
	Endpoint: godeepl.EndpointPro,

    // Login Credentials.
    // When left empty, you need to pass a pre-obtained
    // SessionID.
	Email:    os.Getenv("EMAIL"),
	Password: os.Getenv("PASSWORD"),

	// When the SessionID is empty, Email and Password is used
	// for login and the obtained sessionID is stored in the Client.
	SessionID: os.Getenv("SESSION"),
})

Translate Text

Now, you can use the client to translate text.

You can also pass additional options to the translate endpoint like the desired formality or the ammount of beams (translation alternatives).

res, err := c.Translate(
	godeepl.LangAuto, godeepl.LangEnglish,
	"Jo, was geht ab du alter Sack! Dauert das noch lange?",
	godeepl.TranslationOptions{
		Formality:        godeepl.FormalityFormal,
		PreferedNumBeams: 3,
	})

The returned TranslationResult is an array of translations for each sentence, which again contains a list of beams. There are some utility functions on this object to simplify obtaining the translation results.

For more details, please take a look into the provided examples.


© 2021 Ringo Hoffmann (zekro Development).
Covered by the MIT License.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.