translator

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultEndpoint = "https://api.cognitive.microsofttranslator.com/"
)

Functions

func SimpleRequest

func SimpleRequest(client *http.Client, method, url string, requestBody, responseBody interface{}) (*http.Response, error)

Types

type BingTranslator

type BingTranslator struct {
	BingTranslatorOptions
}

func NewBingTranslator

func NewBingTranslator(options BingTranslatorOptions) (BingTranslator, error)

type BingTranslatorOptions

type BingTranslatorOptions struct {
	KeyA, KeyB, Endpoint string
	Client               *http.Client
}

type LibreOptions

type LibreOptions struct {
	Url, ApiKey string
	Client      *http.Client
}

type LibreTranslateInput

type LibreTranslateInput struct {
	TextSource string `json:"q"`
	SourceLang string `json:"source"`
	TargetLang string `json:"target"`
	Format     string `json:"format"`
	ApiKey     string `json:"api_key,omitempty"`
}

type MockTranlator

type MockTranlator struct{}

func (*MockTranlator) Translate

func (m *MockTranlator) Translate(text, from, to string) (string, error)

type SupportedLanguage

type SupportedLanguage struct {
	Code string `json:"code"`
	Name string `json:"name"`
}

type Translator

type Translator struct {
	SupportedLanguages map[string]string
	sync.RWMutex
	LibreOptions
}

func NewLibreTranslator

func NewLibreTranslator(options ...LibreOptions) (t Translator, err error)

Based on https://libretranslate.com/docs/#/ See also https://github.com/LibreTranslate/LibreTranslate There is also a more complete binding at https://github.com/LibreTranslate/LibreTranslate

func (*Translator) GetLanguages

func (t *Translator) GetLanguages() ([]SupportedLanguage, error)

func (*Translator) IsValidLanguage

func (t *Translator) IsValidLanguage(lang ...string) error

func (*Translator) Translate

func (t *Translator) Translate(text, from, to string) (string, error)

type TranslatorOptions

type TranslatorOptions struct {
	Kind       string
	ApiToken   string
	Endpoint   string
	HttpClient *http.Client
}

type TranslatorProvider

type TranslatorProvider interface {
	Translate(text, from, to string) (string, error)
}

func NewTranslator

func NewTranslator(options TranslatorOptions) (TranslatorProvider, error)

Jump to

Keyboard shortcuts

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