Documentation ¶
Overview ¶
Package translate is an auto-generated package for the Cloud Translation API.
Integrates text translation into your website or application.
Use of Context ¶
The ctx passed to NewClient is used for authentication requests and for creating the underlying connection, but is not used for subsequent calls. Individual methods on the client use the ctx given to them.
To close the open connection, use the Close() method.
For information about setting deadlines, reusing contexts, and more please visit https://pkg.go.dev/cloud.google.com/go.
Index ¶
- func DefaultAuthScopes() []string
- type BatchTranslateTextOperation
- func (op *BatchTranslateTextOperation) Done() bool
- func (op *BatchTranslateTextOperation) Metadata() (*translatepb.BatchTranslateMetadata, error)
- func (op *BatchTranslateTextOperation) Name() string
- func (op *BatchTranslateTextOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*translatepb.BatchTranslateResponse, error)
- func (op *BatchTranslateTextOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*translatepb.BatchTranslateResponse, error)
- type CreateGlossaryOperation
- func (op *CreateGlossaryOperation) Done() bool
- func (op *CreateGlossaryOperation) Metadata() (*translatepb.CreateGlossaryMetadata, error)
- func (op *CreateGlossaryOperation) Name() string
- func (op *CreateGlossaryOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*translatepb.Glossary, error)
- func (op *CreateGlossaryOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*translatepb.Glossary, error)
- type DeleteGlossaryOperation
- func (op *DeleteGlossaryOperation) Done() bool
- func (op *DeleteGlossaryOperation) Metadata() (*translatepb.DeleteGlossaryMetadata, error)
- func (op *DeleteGlossaryOperation) Name() string
- func (op *DeleteGlossaryOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*translatepb.DeleteGlossaryResponse, error)
- func (op *DeleteGlossaryOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*translatepb.DeleteGlossaryResponse, error)
- type GlossaryIterator
- type TranslationCallOptions
- type TranslationClient
- func (c *TranslationClient) BatchTranslateText(ctx context.Context, req *translatepb.BatchTranslateTextRequest, ...) (*BatchTranslateTextOperation, error)
- func (c *TranslationClient) BatchTranslateTextOperation(name string) *BatchTranslateTextOperation
- func (c *TranslationClient) Close() error
- func (c *TranslationClient) Connection() *grpc.ClientConn
- func (c *TranslationClient) CreateGlossary(ctx context.Context, req *translatepb.CreateGlossaryRequest, ...) (*CreateGlossaryOperation, error)
- func (c *TranslationClient) CreateGlossaryOperation(name string) *CreateGlossaryOperation
- func (c *TranslationClient) DeleteGlossary(ctx context.Context, req *translatepb.DeleteGlossaryRequest, ...) (*DeleteGlossaryOperation, error)
- func (c *TranslationClient) DeleteGlossaryOperation(name string) *DeleteGlossaryOperation
- func (c *TranslationClient) DetectLanguage(ctx context.Context, req *translatepb.DetectLanguageRequest, ...) (*translatepb.DetectLanguageResponse, error)
- func (c *TranslationClient) GetGlossary(ctx context.Context, req *translatepb.GetGlossaryRequest, ...) (*translatepb.Glossary, error)
- func (c *TranslationClient) GetSupportedLanguages(ctx context.Context, req *translatepb.GetSupportedLanguagesRequest, ...) (*translatepb.SupportedLanguages, error)
- func (c *TranslationClient) ListGlossaries(ctx context.Context, req *translatepb.ListGlossariesRequest, ...) *GlossaryIterator
- func (c *TranslationClient) TranslateText(ctx context.Context, req *translatepb.TranslateTextRequest, ...) (*translatepb.TranslateTextResponse, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultAuthScopes ¶
func DefaultAuthScopes() []string
DefaultAuthScopes reports the default set of authentication scopes to use with this package.
Types ¶
type BatchTranslateTextOperation ¶
type BatchTranslateTextOperation struct {
// contains filtered or unexported fields
}
BatchTranslateTextOperation manages a long-running operation from BatchTranslateText.
func (*BatchTranslateTextOperation) Done ¶
func (op *BatchTranslateTextOperation) Done() bool
Done reports whether the long-running operation has completed.
func (*BatchTranslateTextOperation) Metadata ¶
func (op *BatchTranslateTextOperation) Metadata() (*translatepb.BatchTranslateMetadata, error)
Metadata returns metadata associated with the long-running operation. Metadata itself does not contact the server, but Poll does. To get the latest metadata, call this method after a successful call to Poll. If the metadata is not available, the returned metadata and error are both nil.
func (*BatchTranslateTextOperation) Name ¶
func (op *BatchTranslateTextOperation) Name() string
Name returns the name of the long-running operation. The name is assigned by the server and is unique within the service from which the operation is created.
func (*BatchTranslateTextOperation) Poll ¶
func (op *BatchTranslateTextOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*translatepb.BatchTranslateResponse, error)
Poll fetches the latest state of the long-running operation.
Poll also fetches the latest metadata, which can be retrieved by Metadata.
If Poll fails, the error is returned and op is unmodified. If Poll succeeds and the operation has completed with failure, the error is returned and op.Done will return true. If Poll succeeds and the operation has completed successfully, op.Done will return true, and the response of the operation is returned. If Poll succeeds and the operation has not completed, the returned response and error are both nil.
func (*BatchTranslateTextOperation) Wait ¶
func (op *BatchTranslateTextOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*translatepb.BatchTranslateResponse, error)
Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
See documentation of Poll for error-handling information.
type CreateGlossaryOperation ¶
type CreateGlossaryOperation struct {
// contains filtered or unexported fields
}
CreateGlossaryOperation manages a long-running operation from CreateGlossary.
func (*CreateGlossaryOperation) Done ¶
func (op *CreateGlossaryOperation) Done() bool
Done reports whether the long-running operation has completed.
func (*CreateGlossaryOperation) Metadata ¶
func (op *CreateGlossaryOperation) Metadata() (*translatepb.CreateGlossaryMetadata, error)
Metadata returns metadata associated with the long-running operation. Metadata itself does not contact the server, but Poll does. To get the latest metadata, call this method after a successful call to Poll. If the metadata is not available, the returned metadata and error are both nil.
func (*CreateGlossaryOperation) Name ¶
func (op *CreateGlossaryOperation) Name() string
Name returns the name of the long-running operation. The name is assigned by the server and is unique within the service from which the operation is created.
func (*CreateGlossaryOperation) Poll ¶
func (op *CreateGlossaryOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*translatepb.Glossary, error)
Poll fetches the latest state of the long-running operation.
Poll also fetches the latest metadata, which can be retrieved by Metadata.
If Poll fails, the error is returned and op is unmodified. If Poll succeeds and the operation has completed with failure, the error is returned and op.Done will return true. If Poll succeeds and the operation has completed successfully, op.Done will return true, and the response of the operation is returned. If Poll succeeds and the operation has not completed, the returned response and error are both nil.
func (*CreateGlossaryOperation) Wait ¶
func (op *CreateGlossaryOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*translatepb.Glossary, error)
Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
See documentation of Poll for error-handling information.
type DeleteGlossaryOperation ¶
type DeleteGlossaryOperation struct {
// contains filtered or unexported fields
}
DeleteGlossaryOperation manages a long-running operation from DeleteGlossary.
func (*DeleteGlossaryOperation) Done ¶
func (op *DeleteGlossaryOperation) Done() bool
Done reports whether the long-running operation has completed.
func (*DeleteGlossaryOperation) Metadata ¶
func (op *DeleteGlossaryOperation) Metadata() (*translatepb.DeleteGlossaryMetadata, error)
Metadata returns metadata associated with the long-running operation. Metadata itself does not contact the server, but Poll does. To get the latest metadata, call this method after a successful call to Poll. If the metadata is not available, the returned metadata and error are both nil.
func (*DeleteGlossaryOperation) Name ¶
func (op *DeleteGlossaryOperation) Name() string
Name returns the name of the long-running operation. The name is assigned by the server and is unique within the service from which the operation is created.
func (*DeleteGlossaryOperation) Poll ¶
func (op *DeleteGlossaryOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*translatepb.DeleteGlossaryResponse, error)
Poll fetches the latest state of the long-running operation.
Poll also fetches the latest metadata, which can be retrieved by Metadata.
If Poll fails, the error is returned and op is unmodified. If Poll succeeds and the operation has completed with failure, the error is returned and op.Done will return true. If Poll succeeds and the operation has completed successfully, op.Done will return true, and the response of the operation is returned. If Poll succeeds and the operation has not completed, the returned response and error are both nil.
func (*DeleteGlossaryOperation) Wait ¶
func (op *DeleteGlossaryOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*translatepb.DeleteGlossaryResponse, error)
Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
See documentation of Poll for error-handling information.
type GlossaryIterator ¶
type GlossaryIterator struct { // Response is the raw response for the current page. // It must be cast to the RPC response type. // Calling Next() or InternalFetch() updates this value. Response interface{} // InternalFetch is for use by the Google Cloud Libraries only. // It is not part of the stable interface of this package. // // InternalFetch returns results from a single call to the underlying RPC. // The number of results is no greater than pageSize. // If there are no more results, nextPageToken is empty and err is nil. InternalFetch func(pageSize int, pageToken string) (results []*translatepb.Glossary, nextPageToken string, err error) // contains filtered or unexported fields }
GlossaryIterator manages a stream of *translatepb.Glossary.
func (*GlossaryIterator) Next ¶
func (it *GlossaryIterator) Next() (*translatepb.Glossary, error)
Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*GlossaryIterator) PageInfo ¶
func (it *GlossaryIterator) PageInfo() *iterator.PageInfo
PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
type TranslationCallOptions ¶
type TranslationCallOptions struct { TranslateText []gax.CallOption DetectLanguage []gax.CallOption GetSupportedLanguages []gax.CallOption BatchTranslateText []gax.CallOption CreateGlossary []gax.CallOption ListGlossaries []gax.CallOption GetGlossary []gax.CallOption DeleteGlossary []gax.CallOption }
TranslationCallOptions contains the retry settings for each method of TranslationClient.
type TranslationClient ¶
type TranslationClient struct { // The call options for this service. CallOptions *TranslationCallOptions // LROClient is used internally to handle long-running operations. // It is exposed so that its CallOptions can be modified if required. // Users should not Close this client. LROClient *lroauto.OperationsClient // contains filtered or unexported fields }
TranslationClient is a client for interacting with Cloud Translation API. Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
Provides natural language translation operations.
func NewTranslationClient ¶
func NewTranslationClient(ctx context.Context, opts ...option.ClientOption) (*TranslationClient, error)
NewTranslationClient creates a new translation service client based on gRPC. The returned client must be Closed when it is done being used to clean up its underlying connections.
Provides natural language translation operations.
Example ¶
package main import ( "context" translate "cloud.google.com/go/translate/apiv3" ) func main() { ctx := context.Background() c, err := translate.NewTranslationClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() // TODO: Use client. _ = c }
Output:
func (*TranslationClient) BatchTranslateText ¶
func (c *TranslationClient) BatchTranslateText(ctx context.Context, req *translatepb.BatchTranslateTextRequest, opts ...gax.CallOption) (*BatchTranslateTextOperation, error)
BatchTranslateText translates a large volume of text in asynchronous batch mode. This function provides real-time output as the inputs are being processed. If caller cancels a request, the partial results (for an input file, it’s all or nothing) may still be available on the specified output location.
This call returns immediately and you can use google.longrunning.Operation.name (at http://google.longrunning.Operation.name) to poll the status of the call.
Example ¶
package main import ( "context" translate "cloud.google.com/go/translate/apiv3" translatepb "google.golang.org/genproto/googleapis/cloud/translate/v3" ) func main() { ctx := context.Background() c, err := translate.NewTranslationClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &translatepb.BatchTranslateTextRequest{ // TODO: Fill request struct fields. } op, err := c.BatchTranslateText(ctx, req) if err != nil { // TODO: Handle error. } resp, err := op.Wait(ctx) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output:
func (*TranslationClient) BatchTranslateTextOperation ¶
func (c *TranslationClient) BatchTranslateTextOperation(name string) *BatchTranslateTextOperation
BatchTranslateTextOperation returns a new BatchTranslateTextOperation from a given name. The name must be that of a previously created BatchTranslateTextOperation, possibly from a different process.
func (*TranslationClient) Close ¶
func (c *TranslationClient) Close() error
Close closes the connection to the API service. The user should invoke this when the client is no longer required.
func (*TranslationClient) Connection ¶
func (c *TranslationClient) Connection() *grpc.ClientConn
Connection returns a connection to the API service.
Deprecated.
func (*TranslationClient) CreateGlossary ¶
func (c *TranslationClient) CreateGlossary(ctx context.Context, req *translatepb.CreateGlossaryRequest, opts ...gax.CallOption) (*CreateGlossaryOperation, error)
CreateGlossary creates a glossary and returns the long-running operation. Returns NOT_FOUND, if the project doesn’t exist.
Example ¶
package main import ( "context" translate "cloud.google.com/go/translate/apiv3" translatepb "google.golang.org/genproto/googleapis/cloud/translate/v3" ) func main() { ctx := context.Background() c, err := translate.NewTranslationClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &translatepb.CreateGlossaryRequest{ // TODO: Fill request struct fields. } op, err := c.CreateGlossary(ctx, req) if err != nil { // TODO: Handle error. } resp, err := op.Wait(ctx) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output:
func (*TranslationClient) CreateGlossaryOperation ¶
func (c *TranslationClient) CreateGlossaryOperation(name string) *CreateGlossaryOperation
CreateGlossaryOperation returns a new CreateGlossaryOperation from a given name. The name must be that of a previously created CreateGlossaryOperation, possibly from a different process.
func (*TranslationClient) DeleteGlossary ¶
func (c *TranslationClient) DeleteGlossary(ctx context.Context, req *translatepb.DeleteGlossaryRequest, opts ...gax.CallOption) (*DeleteGlossaryOperation, error)
DeleteGlossary deletes a glossary, or cancels glossary construction if the glossary isn’t created yet. Returns NOT_FOUND, if the glossary doesn’t exist.
Example ¶
package main import ( "context" translate "cloud.google.com/go/translate/apiv3" translatepb "google.golang.org/genproto/googleapis/cloud/translate/v3" ) func main() { ctx := context.Background() c, err := translate.NewTranslationClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &translatepb.DeleteGlossaryRequest{ // TODO: Fill request struct fields. } op, err := c.DeleteGlossary(ctx, req) if err != nil { // TODO: Handle error. } resp, err := op.Wait(ctx) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output:
func (*TranslationClient) DeleteGlossaryOperation ¶
func (c *TranslationClient) DeleteGlossaryOperation(name string) *DeleteGlossaryOperation
DeleteGlossaryOperation returns a new DeleteGlossaryOperation from a given name. The name must be that of a previously created DeleteGlossaryOperation, possibly from a different process.
func (*TranslationClient) DetectLanguage ¶
func (c *TranslationClient) DetectLanguage(ctx context.Context, req *translatepb.DetectLanguageRequest, opts ...gax.CallOption) (*translatepb.DetectLanguageResponse, error)
DetectLanguage detects the language of text within a request.
Example ¶
package main import ( "context" translate "cloud.google.com/go/translate/apiv3" translatepb "google.golang.org/genproto/googleapis/cloud/translate/v3" ) func main() { ctx := context.Background() c, err := translate.NewTranslationClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &translatepb.DetectLanguageRequest{ // TODO: Fill request struct fields. } resp, err := c.DetectLanguage(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output:
func (*TranslationClient) GetGlossary ¶
func (c *TranslationClient) GetGlossary(ctx context.Context, req *translatepb.GetGlossaryRequest, opts ...gax.CallOption) (*translatepb.Glossary, error)
GetGlossary gets a glossary. Returns NOT_FOUND, if the glossary doesn’t exist.
Example ¶
package main import ( "context" translate "cloud.google.com/go/translate/apiv3" translatepb "google.golang.org/genproto/googleapis/cloud/translate/v3" ) func main() { ctx := context.Background() c, err := translate.NewTranslationClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &translatepb.GetGlossaryRequest{ // TODO: Fill request struct fields. } resp, err := c.GetGlossary(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output:
func (*TranslationClient) GetSupportedLanguages ¶
func (c *TranslationClient) GetSupportedLanguages(ctx context.Context, req *translatepb.GetSupportedLanguagesRequest, opts ...gax.CallOption) (*translatepb.SupportedLanguages, error)
GetSupportedLanguages returns a list of supported languages for translation.
Example ¶
package main import ( "context" translate "cloud.google.com/go/translate/apiv3" translatepb "google.golang.org/genproto/googleapis/cloud/translate/v3" ) func main() { ctx := context.Background() c, err := translate.NewTranslationClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &translatepb.GetSupportedLanguagesRequest{ // TODO: Fill request struct fields. } resp, err := c.GetSupportedLanguages(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output:
func (*TranslationClient) ListGlossaries ¶
func (c *TranslationClient) ListGlossaries(ctx context.Context, req *translatepb.ListGlossariesRequest, opts ...gax.CallOption) *GlossaryIterator
ListGlossaries lists glossaries in a project. Returns NOT_FOUND, if the project doesn’t exist.
Example ¶
package main import ( "context" translate "cloud.google.com/go/translate/apiv3" "google.golang.org/api/iterator" translatepb "google.golang.org/genproto/googleapis/cloud/translate/v3" ) func main() { ctx := context.Background() c, err := translate.NewTranslationClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &translatepb.ListGlossariesRequest{ // TODO: Fill request struct fields. } it := c.ListGlossaries(ctx, req) for { resp, err := it.Next() if err == iterator.Done { break } if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp } }
Output:
func (*TranslationClient) TranslateText ¶
func (c *TranslationClient) TranslateText(ctx context.Context, req *translatepb.TranslateTextRequest, opts ...gax.CallOption) (*translatepb.TranslateTextResponse, error)
TranslateText translates input text and returns translated text.
Example ¶
package main import ( "context" translate "cloud.google.com/go/translate/apiv3" translatepb "google.golang.org/genproto/googleapis/cloud/translate/v3" ) func main() { ctx := context.Background() c, err := translate.NewTranslationClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &translatepb.TranslateTextRequest{ // TODO: Fill request struct fields. } resp, err := c.TranslateText(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output: