deepl

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServerURLPro  = "https://api.deepl.com/v2"
	ServerURLFree = "https://api-free.deepl.com/v2"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(timeout time.Duration) *Client

type DocumentInfo added in v0.4.0

type DocumentInfo struct {
	DocumentId  string `json:"document_id"`
	DocumentKey string `json:"document_key"`
}

type DocumentStatus added in v0.4.0

type DocumentStatus struct {
	DocumentId string `json:"document_id"`
	Status     string `json:"status"`

	// Status dependent additional fields
	SecondsRemaining string `json:"seconds_remaining:"`
	BilledCharacters int    `json:"billed_characters"`
	Message          string `json:"message"`
}

type GlossaryEntry added in v0.3.0

type GlossaryEntry struct {
	Source string
	Target string
}

type GlossaryInfo added in v0.3.0

type GlossaryInfo struct {
	GlossaryId   string `json:"glossary_id"`
	Name         string `json:"name"`
	Ready        bool   `json:"ready"`
	SourceLang   string `json:"source_lang"`
	TargetLang   string `json:"target_lang"`
	CreationTime string `json:"creation_time"`
	EntryCount   int    `json:"entry_count"`
}

type HTTPError

type HTTPError struct {
	StatusCode int
}

func (HTTPError) Error

func (err HTTPError) Error() string

type Language added in v0.2.0

type Language struct {
	Code              string `json:"language"`
	Name              string `json:"name"`
	SupportsFormality bool   `json:"supports_formality"`
}

type LanguagePair added in v0.3.0

type LanguagePair struct {
	SourceLang string `json:"source_lang"`
	TargetLang string `json:"target_lang"`
}

type TranslateOption

type TranslateOption struct {
	Key   string
	Value string
}

TranslateOption is a key-value pair for configuring text translation parameters

func Formality

func Formality(formality string) (*TranslateOption, error)

Formality sets whether the translated text should lean towards formal or informal language

func GlossaryId

func GlossaryId(glossary string) (*TranslateOption, error)

GlossaryId specifies the glossary to use for the translation

func IgnoreTags

func IgnoreTags(tags string) (*TranslateOption, error)

IgnoeTags specifies a comma-separated list of XML tags that indicate text not to be translated

func NonSplittingTags

func NonSplittingTags(tags string) (*TranslateOption, error)

NonSplittingTags specifies a comma-separated list of XML tags which never split sentences

func OutlineDetection

func OutlineDetection(detect string) (*TranslateOption, error)

OutlineDetection can be used to disable the automatic detection of the XML structure

func PreserveFormatting

func PreserveFormatting(preserve string) (*TranslateOption, error)

PreserveFormatting sets whether the translation engine should respect the original formatting, even if it would usually correct some aspects

func SourceLang

func SourceLang(lang string) (*TranslateOption, error)

The language to be translated. If this parameter is omitted, the API will attempt to detect the language of the text and translate it

func SplitSentences

func SplitSentences(split string) (*TranslateOption, error)

SplitSentences sets whether the translation engine should first split the input into sentences

func SplittingTags

func SplittingTags(tags string) (*TranslateOption, error)

SplittingTags specifies a comma-separated list of XML tags which always cause splts

func TagHandling

func TagHandling(handling string) (*TranslateOption, error)

TagHandling sets which kind of tags should be handled

type Translation

type Translation struct {
	DetectedSourceLanguage string `json:"detected_source_language"`
	Text                   string `json:"text"`
}

type Translator

type Translator struct {
	// contains filtered or unexported fields
}

func NewTranslator

func NewTranslator(authKey string, opts ...TranslatorOption) (*Translator, error)

NewTranslator creates a new translator

func (*Translator) CreateGlossary added in v0.3.0

func (t *Translator) CreateGlossary(name string, sourceLang string, targetLang string, entries []GlossaryEntry) (*GlossaryInfo, error)

func (*Translator) DeleteGlossary added in v0.3.0

func (t *Translator) DeleteGlossary(glossaryId string) error

func (*Translator) GetGlossary added in v0.3.0

func (t *Translator) GetGlossary(glossaryId string) (*GlossaryInfo, error)

func (*Translator) GetGlossaryEntries added in v0.3.0

func (t *Translator) GetGlossaryEntries(glossaryId string) ([]GlossaryEntry, error)

func (*Translator) GetGlossaryLanguagePairs added in v0.3.0

func (t *Translator) GetGlossaryLanguagePairs() ([]LanguagePair, error)

func (*Translator) GetLanguages added in v0.2.0

func (t *Translator) GetLanguages(langType string) ([]Language, error)

func (*Translator) GetUsage added in v0.2.0

func (t *Translator) GetUsage() (*Usage, error)

func (*Translator) ListGlossaries added in v0.3.0

func (t *Translator) ListGlossaries() ([]GlossaryInfo, error)

func (*Translator) TranslateDocumentDownload added in v0.4.0

func (t *Translator) TranslateDocumentDownload(id string, key string) (*io.PipeReader, error)

func (*Translator) TranslateDocumentStatus added in v0.4.0

func (t *Translator) TranslateDocumentStatus(id string, key string) (*DocumentStatus, error)

func (*Translator) TranslateDocumentUpload added in v0.4.0

func (t *Translator) TranslateDocumentUpload(filePath string, targetLang string, options ...TranslateOption) (*DocumentInfo, error)

func (*Translator) TranslateText

func (t *Translator) TranslateText(texts []string, targetLang string, options ...TranslateOption) ([]Translation, error)

TranslateText translates the given text(s) into the specified target language

type TranslatorOption added in v0.4.0

type TranslatorOption func(*Translator) error

TranslatorOption is a functional option for configuring the Translator

func ServerURL added in v0.4.0

func ServerURL(url string) TranslatorOption

ServerURL allows overriding the default server url

type Usage added in v0.2.0

type Usage struct {
	CharacterCount    int `json:"character_count"`
	CharacterLimit    int `json:"character_limit"`
	DocumentCount     int `json:"document_count"`
	DocumentLimit     int `json:"document_limit"`
	TeamDocumentCount int `json:"team_document_count"`
	TeamDocumentLimit int `json:"team_document_limit"`
}

Jump to

Keyboard shortcuts

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