1// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT. 2 3package translate 4 5import ( 6 "github.com/aws/aws-sdk-go/aws" 7 "github.com/aws/aws-sdk-go/aws/awsutil" 8 "github.com/aws/aws-sdk-go/aws/request" 9) 10 11const opText = "TranslateText" 12 13// TextRequest generates a "aws/request.Request" representing the 14// client's request for the Text operation. The "output" return 15// value will be populated with the request's response once the request complets 16// successfuly. 17// 18// Use "Send" method on the returned Request to send the API call to the service. 19// the "output" return value is not valid until after Send returns without error. 20// 21// See Text for more information on using the Text 22// API call, and error handling. 23// 24// This method is useful when you want to inject custom logic or configuration 25// into the SDK's request lifecycle. Such as custom headers, or retry logic. 26// 27// 28// // Example sending a request using the TextRequest method. 29// req, resp := client.TextRequest(params) 30// 31// err := req.Send() 32// if err == nil { // resp is now filled 33// fmt.Println(resp) 34// } 35// 36// See also, https://docs.aws.amazon.com/goto/WebAPI/translate-2017-07-01/Text 37func (c *Translate) TextRequest(input *TextInput) (req *request.Request, output *TextOutput) { 38 op := &request.Operation{ 39 Name: opText, 40 HTTPMethod: "POST", 41 HTTPPath: "/", 42 } 43 44 if input == nil { 45 input = &TextInput{} 46 } 47 48 output = &TextOutput{} 49 req = c.newRequest(op, input, output) 50 return 51} 52 53// Text API operation for Amazon Translate. 54// 55// Translates input text from the source language to the target language. You 56// can translate between English (en) and one of the following languages, or 57// between one of the following languages and English. 58// 59// * Arabic (ar) 60// 61// * Chinese (Simplified) (zh) 62// 63// * French (fr) 64// 65// * German (de) 66// 67// * Portuguese (pt) 68// 69// * Spanish (es) 70// 71// Returns awserr.Error for service API and SDK errors. Use runtime type assertions 72// with awserr.Error's Code and Message methods to get detailed information about 73// the error. 74// 75// See the AWS API reference guide for Amazon Translate's 76// API operation Text for usage and error information. 77// 78// Returned Error Codes: 79// * ErrCodeInvalidRequestException "InvalidRequestException" 80// The request is invalid. 81// 82// * ErrCodeTextSizeLimitExceededException "TextSizeLimitExceededException" 83// The size of the input text exceeds the length constraint for the Text field. 84// Try again with a shorter text. 85// 86// * ErrCodeTooManyRequestsException "TooManyRequestsException" 87// The number of requests exceeds the limit. Resubmit your request later. 88// 89// * ErrCodeUnsupportedLanguagePairException "UnsupportedLanguagePairException" 90// Amazon Translate cannot translate input text in the source language into 91// this target language. For more information, see how-to-error-msg. 92// 93// * ErrCodeInternalServerException "InternalServerException" 94// An internal server error occurred. Retry your request. 95// 96// * ErrCodeServiceUnavailableException "ServiceUnavailableException" 97// Amazon Translate is unavailable. Retry your request later. 98// 99// See also, https://docs.aws.amazon.com/goto/WebAPI/translate-2017-07-01/Text 100func (c *Translate) Text(input *TextInput) (*TextOutput, error) { 101 req, out := c.TextRequest(input) 102 return out, req.Send() 103} 104 105// TextWithContext is the same as Text with the addition of 106// the ability to pass a context and additional request options. 107// 108// See Text for details on how to use this API operation. 109// 110// The context must be non-nil and will be used for request cancellation. If 111// the context is nil a panic will occur. In the future the SDK may create 112// sub-contexts for http.Requests. See https://golang.org/pkg/context/ 113// for more information on using Contexts. 114func (c *Translate) TextWithContext(ctx aws.Context, input *TextInput, opts ...request.Option) (*TextOutput, error) { 115 req, out := c.TextRequest(input) 116 req.SetContext(ctx) 117 req.ApplyOptions(opts...) 118 return out, req.Send() 119} 120 121// See also, https://docs.aws.amazon.com/goto/WebAPI/translate-2017-07-01/TextRequest 122type TextInput struct { 123 _ struct{} `type:"structure"` 124 125 // One of the supported language codes for the source text. If the TargetLanguageCode 126 // is not "en", the SourceLanguageCode must be "en". 127 // 128 // SourceLanguageCode is a required field 129 SourceLanguageCode *string `min:"2" type:"string" required:"true"` 130 131 // One of the supported language codes for the target text. If the SourceLanguageCode 132 // is not "en", the TargetLanguageCode must be "en". 133 // 134 // TargetLanguageCode is a required field 135 TargetLanguageCode *string `min:"2" type:"string" required:"true"` 136 137 // The text to translate. 138 // 139 // Text is a required field 140 Text *string `min:"1" type:"string" required:"true"` 141} 142 143// String returns the string representation 144func (s TextInput) String() string { 145 return awsutil.Prettify(s) 146} 147 148// GoString returns the string representation 149func (s TextInput) GoString() string { 150 return s.String() 151} 152 153// Validate inspects the fields of the type to determine if they are valid. 154func (s *TextInput) Validate() error { 155 invalidParams := request.ErrInvalidParams{Context: "TextInput"} 156 if s.SourceLanguageCode == nil { 157 invalidParams.Add(request.NewErrParamRequired("SourceLanguageCode")) 158 } 159 if s.SourceLanguageCode != nil && len(*s.SourceLanguageCode) < 2 { 160 invalidParams.Add(request.NewErrParamMinLen("SourceLanguageCode", 2)) 161 } 162 if s.TargetLanguageCode == nil { 163 invalidParams.Add(request.NewErrParamRequired("TargetLanguageCode")) 164 } 165 if s.TargetLanguageCode != nil && len(*s.TargetLanguageCode) < 2 { 166 invalidParams.Add(request.NewErrParamMinLen("TargetLanguageCode", 2)) 167 } 168 if s.Text == nil { 169 invalidParams.Add(request.NewErrParamRequired("Text")) 170 } 171 if s.Text != nil && len(*s.Text) < 1 { 172 invalidParams.Add(request.NewErrParamMinLen("Text", 1)) 173 } 174 175 if invalidParams.Len() > 0 { 176 return invalidParams 177 } 178 return nil 179} 180 181// SetSourceLanguageCode sets the SourceLanguageCode field's value. 182func (s *TextInput) SetSourceLanguageCode(v string) *TextInput { 183 s.SourceLanguageCode = &v 184 return s 185} 186 187// SetTargetLanguageCode sets the TargetLanguageCode field's value. 188func (s *TextInput) SetTargetLanguageCode(v string) *TextInput { 189 s.TargetLanguageCode = &v 190 return s 191} 192 193// SetText sets the Text field's value. 194func (s *TextInput) SetText(v string) *TextInput { 195 s.Text = &v 196 return s 197} 198 199// See also, https://docs.aws.amazon.com/goto/WebAPI/translate-2017-07-01/TextResponse 200type TextOutput struct { 201 _ struct{} `type:"structure"` 202 203 // The language code for the language of the input text. 204 // 205 // SourceLanguageCode is a required field 206 SourceLanguageCode *string `min:"2" type:"string" required:"true"` 207 208 // The language code for the language of the translated text. 209 // 210 // TargetLanguageCode is a required field 211 TargetLanguageCode *string `min:"2" type:"string" required:"true"` 212 213 // The text translated into the target language. 214 // 215 // TranslatedText is a required field 216 TranslatedText *string `min:"1" type:"string" required:"true"` 217} 218 219// String returns the string representation 220func (s TextOutput) String() string { 221 return awsutil.Prettify(s) 222} 223 224// GoString returns the string representation 225func (s TextOutput) GoString() string { 226 return s.String() 227} 228 229// SetSourceLanguageCode sets the SourceLanguageCode field's value. 230func (s *TextOutput) SetSourceLanguageCode(v string) *TextOutput { 231 s.SourceLanguageCode = &v 232 return s 233} 234 235// SetTargetLanguageCode sets the TargetLanguageCode field's value. 236func (s *TextOutput) SetTargetLanguageCode(v string) *TextOutput { 237 s.TargetLanguageCode = &v 238 return s 239} 240 241// SetTranslatedText sets the TranslatedText field's value. 242func (s *TextOutput) SetTranslatedText(v string) *TextOutput { 243 s.TranslatedText = &v 244 return s 245} 246