deepl

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: MIT Imports: 11 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/tiny-lib/deepl"
translateResp, err := Translate("", "zh", "I love Go programming language")
	if err != nil {
		t.Fatal(err)
	}
log.Println(translateResp.Result.Texts[0].Text)

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) (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 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