Documentation
¶
Overview ¶
Package deeplapi provides a wrapper around the official DeepL API. You can translate text and retrieve available languages. An API key is required. Both free and paid tiers are supported.
Index ¶
Constants ¶
const ( FormalityDefault = "default" FormalityMore = "more" FormalityLess = "less" FormalityPreferMore = "prefer_more" FormalityPreferLess = "prefer_less" )
Defines the formality of the translated text. Not supported by all languages.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DeeplAPI ¶
type DeeplAPI struct {
// contains filtered or unexported fields
}
DeeplAPI provides abstract access to the official DeepL API
func (*DeeplAPI) GetLanguages ¶
func (api *DeeplAPI) GetLanguages() (*GetLanguagesResp, error)
The GetLanguages function retrieves all languages that DeepL supports Because supported source and target languages may differ, the reponse differentiates between them
func (*DeeplAPI) Translate ¶
func (api *DeeplAPI) Translate(params TranslateParams) (*TranslateResp, error)
The Translate function uses DeepL to translate params.Text into the specified language
type GetLanguagesResp ¶
Response type for DeeplAPI.GetLanguages
type Language ¶
type Language struct {
Language string `json:"language"` // Language code
Name string `json:"name"` // Friendly name
SupportsFormality bool `json:"supports_formality"` // Whether DeepL supports specifying a formality or not (when used as target langauge)
}
Language represents a language that is supported by DeepL Beware of the fact that DeepL does support different languages as source and target languages.
type TranslateParams ¶
type TranslateParams struct {
Text []string `json:"text"` // Text to translate, UTF-8
SourceLang string `json:"source_lang"` // Original language code, optional
TargetLang string `json:"target_lang"` // Target Language code
Context string `json:"context"` // Additional context that influences the translation, but is not translated itself, optional
Formality string `json:"formality"` // Define whether the text should be formal or more informal, not supported by all languages, optional
}
Parameters for DeeplAPI.Translate Text and TargetLang are required
type TranslateResp ¶
type TranslateResp struct {
Translations []struct {
DetectedSourceLanguage string `json:"detected_source_language"`
Text string `json:"text"`
} `json:"translations"`
}
Response type for DeeplAPI.Translate