deepl

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: MIT Imports: 16 Imported by: 0

README

deepl

free deepl translate api in go

Go Report Card

reference deepLX ,Reverse-engineering the DeepL Windows client has improved several details.

deepL windows Client download Url: https://appdownload.deepl.com/windows/0install/deepl.xml

Example:

import "github.com/lib-x/deepl"
translateResp, err := Translate("", "zh", "I love Go programming language")
	if err != nil {
		t.Fatal(err)
	}
log.Println(translateResp.Result.Texts[0].Text)

also you an set proxy to use the deepl lib.see in the test

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorNoTranslateTextFound = errors.New("no Translate Text Found")
	ErrorInvalidTargetLang    = errors.New("invalid Target Lang")
	ErrorTooManyRequests      = errors.New("too Many Requests")

	ErrorInvalidResponse = errors.New("invalid response")
)

Functions

This section is empty.

Types

type CommonJobParameters

type CommonJobParameters struct {
	WasSpoken       bool   `json:"wasSpoken,omitempty"`
	TranscribeAS    string `json:"transcribe_as,omitempty"`
	RegionalVariant string `json:"regionalVariant,omitempty"`
}

type ErrorInfo

type ErrorInfo struct {
	ErrorCode int `json:"code"`
}

type JsonRpcRequest

type JsonRpcRequest struct {
	Jsonrpc string                              `json:"jsonrpc"`
	Method  string                              `json:"method"`
	Id      int64                               `json:"id"`
	Params  TextTranslationJsonRpcRequestParams `json:"params"`
}

type JsonRpcResponse

type JsonRpcResponse struct {
	Jsonrpc   string                      `json:"jsonrpc"`
	Id        int64                       `json:"id"`
	Result    TextTranslationJsonResponse `json:"result"`
	ErrorInfo *ErrorInfo                  `json:"error,omitempty"`
}

func Translate

func Translate(sourceLanguage, targetLanguage, textToTranslate string, options ...Option) (jsonRpcResponse *JsonRpcResponse, err error)

Translate request data. support lang code using deepL api DE: German EN: English ES: Spanish FR: French IT: Italian JA: Japanese NL: Dutch PL: Polish PT: Portuguese RU: Russian ZH: Chinese BG: Bulgarian CS: Czech DA: Danish EL: Greek ET: Estonian FI: Finnish HU: Hungarian LT: Lithuanian LV: Latvian RO: Romanian SK: Slovakian SL: Slovenian SV: Swedish

type Lang

type Lang struct {
	SourceLangUserSelected string `json:"source_lang_user_selected"`
	TargetLang             string `json:"target_lang"`
}

type Option

type Option func(option *deepLClientOption)

func WithHttpProxy

func WithHttpProxy(proxy string) Option

WithHttpProxy set http proxy.if both httpProxy and sock5 proxy are set, http proxy will be over-wrote by sock5 proxy .example http://127.0.0.1:1080

func WithHttpProxyEx added in v1.0.5

func WithHttpProxyEx(proxy string, ignoreSSLVerification bool) Option

WithHttpProxyEx set http proxy.if both httpProxy and sock5 proxy are set, http proxy will be over-wrote by sock5 proxy .example http://http://127.0.0.1:1080 ignoreSSLVerification: ignore SSL verification

func WithSocket5Proxy

func WithSocket5Proxy(socket5Proxy string, userName string, password string) Option

WithSocket5Proxy set socket5Proxy.if both httpProxy and sock5 proxy are set, http proxy will be over-wrote by sock5 proxy example 127.0.0.1:1080

func WithSocket5ProxyEx added in v1.0.5

func WithSocket5ProxyEx(socket5Proxy string, userName string, password string, ignoreSSLVerification bool) Option

WithSocket5ProxyEx set socket5Proxy.if both httpProxy and sock5 proxy are set, http proxy will be over-wrote by sock5 proxy example 127.0.0.1:1080 ignoreSSLVerification: ignore SSL verification

type Text

type Text struct {
	Text string `json:"text"`
}

type TextParam

type TextParam struct {
	Text
	RequestAlternatives int `json:"requestAlternatives,omitempty"`
}

type TextTranslationJsonResponse

type TextTranslationJsonResponse struct {
	Texts               []TextWithAlternatives `json:"texts"`
	LanguageCode        string                 `json:"lang"`
	LanguageIsConfident bool                   `json:"lang_is_confident"`
	DetectedLanguages   map[string]float64     `json:"detectedLanguages"`
}

type TextTranslationJsonRpcRequestParams

type TextTranslationJsonRpcRequestParams struct {
	Texts           []TextParam         `json:"texts"`
	Splitting       string              `json:"splitting"`
	Lang            Lang                `json:"lang"`
	Timestamp       int64               `json:"timestamp"`
	CommonJobParams CommonJobParameters `json:"commonJobParams"`
}

type TextWithAlternatives

type TextWithAlternatives struct {
	Text
	Alternatives []Text `json:"alternatives,omitempty"`
}

Jump to

Keyboard shortcuts

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