translate

package
v0.0.0-...-1a6ade9 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2016 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package translate is a client for the Google Translate API. See https://cloud.google.com/translate for details.

This package is experimental and subject to change without notice.

Index

Constants

Scope is the OAuth2 scope required by the Google Cloud Vision API.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a client for the translate API.

func NewClient

func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error)

NewClient constructs a new Client that can perform Translate operations.

You can find or create API key for your project from the Credentials page of the Developers Console (console.developers.google.com).

func (*Client) Close

func (c *Client) Close() error

Close closes any resources held by the client. Close should be called when the client is no longer needed. It need not be called at program exit.

func (*Client) DetectLanguage

func (c *Client) DetectLanguage(ctx context.Context, inputs []string) ([][]Detection, error)

DetectLanguage attempts to determine the language of the inputs. Each input string may be in a different language.

Each slice of Detections in the return value corresponds with one input string. A slice of Detections holds multiple hypotheses for the language of a single input string.

func (*Client) SupportedLanguages

func (c *Client) SupportedLanguages(ctx context.Context, target language.Tag) ([]Language, error)

SupportedLanguages returns a list of supported languages for translation. The target parameter is the language to use to return localized, human readable names of supported languages.

func (*Client) Translate

func (c *Client) Translate(ctx context.Context, inputs []string, target language.Tag, opts *Options) ([]Translation, error)

Translate one or more strings of text from a source language to a target language. All inputs must be in the same language.

The target parameter supplies the language to translate to. The supported languages are listed at https://cloud.google.com/translate/v2/translate-reference#supported_languages. You can also call the SupportedLanguages method.

The returned Translations appear in the same order as the inputs.

type Detection

type Detection struct {
	// Language is the code of the language detected.
	Language language.Tag

	// Confidence is a number from 0 to 1, with higher numbers indicating more
	// confidence in the detection.
	Confidence float64

	// IsReliable indicates whether the language detection result is reliable.
	IsReliable bool
}

Detection represents information about a language detected in an input.

type Format

type Format string

The format of the input text. Used in Options.Format.

const (
	HTML Format = "html"
	Text Format = "text"
)

Constants for Options.Format.

type Language

type Language struct {
	// Name is the human-readable name of the language.
	Name string

	// Tag is a standard code for the language.
	Tag language.Tag
}

A Language describes a language supported for translation.

type Options

type Options struct {
	// Source is the language of the input strings. If empty, the service will
	// attempt to identify the source language automatically and return it within
	// the response.
	Source language.Tag

	// Format describes the format of the input texts. The choices are HTML or
	// Text. The default is HTML.
	Format Format

	// The model to use for translation. The choices are "nmt" or "base". The
	// default is "base".
	Model string
}

Options contains options for Translate.

type Translation

type Translation struct {
	// Text is the input text translated into the target language.
	Text string

	// Source is the detected language of the input text, if source was
	// not supplied to Client.Translate. If source was supplied, this field
	// will be empty.
	Source language.Tag

	// Model is the model that was used for translation.
	// It may not match the model provided as an option to Client.Translate.
	Model string
}

A Translation contains the results of translating a piece of text.

Directories

Path Synopsis
internal
translate/v2
Package translate provides access to the Translate API.
Package translate provides access to the Translate API.

Jump to

Keyboard shortcuts

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