microsoft

package
v0.0.0-...-862d6eb Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTranslator

func NewTranslator(subscriptionKey string) translator.Translator

NewTranslator returns a struct that implements the Translator interface by exposing a Translate and a Languages function that are backed by Microsoft's translation API. The function takes the subscriptionKey for a registered Text Translation Service. Details on how to get such a key: http://docs.microsofttranslator.com/text-translate.html.

Types

type Alternatives

type Alternatives struct {
	Language                   string  `json:"language"`
	Score                      float64 `json:"score"`
	IsTranslationSupported     bool    `json:"isTranslationSupported"`
	IsTransliterationSupported bool    `json:"isTransliterationSupported"`
}

type Detect

type Detect []struct {
	Language                   string         `json:"language"`
	Score                      float64        `json:"score"`
	IsTranslationSupported     bool           `json:"isTranslationSupported"`
	IsTransliterationSupported bool           `json:"isTransliterationSupported"`
	Alternatives               []Alternatives `json:"alternatives"`
}

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

type Errors

type Errors struct {
	Error Error `json:"error"`
}

type LanguageCatalog

type LanguageCatalog interface {
	Languages() ([]translator.Language, error)
}

The LanguageCatalog provides a slice of languages representing all languages supported by Microsoft's Translation API.

type LanguageProvider

type LanguageProvider interface {
	Codes() ([]string, error)
	Names(codes []string) ([]string, error)
}

The LanguageProvider retrieves the names and codes of all languages supported by Microsoft's Translation API.

type Request

type Request []struct {
	Text string `json:"Text"`
}

type Router

type Router interface {
	AuthURL() string
	TranslationURL() string
	DetectURL() string
	LanguageNamesURL() string
	LanguageCodesURL() string
	ApiVersion() string
}

The Router provides necessary URLs to communicate with Microsoft's API.

type Translate

type Translate []struct {
	Translations []Translations `json:"translations"`
}

type TranslationProvider

type TranslationProvider interface {
	Translate(text, from, to, version string) (string, error)
	Detect(text, version string) (string, error)
}

The TranslationProvider communicates with Microsoft's API to provide a translation for a given text.

type Translations

type Translations struct {
	Text string `json:"text"`
	To   string `json:"to"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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