translate

package module
v0.0.0-...-68755d2 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2018 License: MIT Imports: 5 Imported by: 0

README

Build Status GoDoc Go Report Card Coverage Status

go-yandex-translate

Go Yandex Translate API wrapper

Usage:

package main

import (
  "fmt"
  "github.com/dafanasev/go-yandex-translate"
)

func main() {
  tr := translate.New(YOUR_API_KEY)

  response, err := tr.GetLangs("en")
  if err != nil {
    fmt.Println(err)
  } else {
    fmt.Println(response.Langs)
    fmt.Println(response.Dirs)
  }

  translation, err := tr.Translate("ru", "A lazy dog")
  if err != nil {
    fmt.Println(err)
  } else {
    fmt.Println(translation.Result())
  }
}

Documentation

Overview

Package translate is the Yandex.Translate API client

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Languages

type Languages struct {
	Code    int
	Message string
	Dirs    []string
	Langs   map[string]string
}

Languages holds GetLangs method response

type Response

type Response struct {
	Code     int
	Message  string
	Lang     string
	Text     []string
	Detected map[string]string
}

Response holds Translate method response

func (*Response) Result

func (response *Response) Result() string

Result returns translation as a string

type Translator

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

Translator holds api key

func New

func New(apiKey string) *Translator

New returns translator instance

func (*Translator) GetLangs

func (tr *Translator) GetLangs(ui string) (*Languages, error)

GetLangs returns supported languages

func (*Translator) Translate

func (tr *Translator) Translate(lang, text string) (*Response, error)

Translate returns translation for the request

Jump to

Keyboard shortcuts

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