TranslateText - Amazon Translate API Reference

TranslateText

Translates input text from the source language to the target language. For a list of available languages and language codes, see Supported languages in the Amazon Translate Developer Guide.

Request Syntax

{ "Settings": { "Brevity": "string", "Formality": "string", "Profanity": "string" }, "SourceLanguageCode": "string", "TargetLanguageCode": "string", "TerminologyNames": [ "string" ], "Text": "string" }

Request Parameters

For information about the parameters that are common to all actions, see Common Parameters.

The request accepts the following data in JSON format.

Settings

Settings to configure your translation output. You can configure the following options:

  • Brevity: reduces the length of the translated output for most translations.

  • Formality: sets the formality level of the output text.

  • Profanity: masks profane words and phrases in your translation output.

Type: TranslationSettings object

Required: No

SourceLanguageCode

The language code for the language of the source text. For a list of language codes, see Supported languages in the Amazon Translate Developer Guide.

To have Amazon Translate determine the source language of your text, you can specify auto in the SourceLanguageCode field. If you specify auto, Amazon Translate will call Amazon Comprehend to determine the source language.

Note

If you specify auto, you must send the TranslateText request in a region that supports Amazon Comprehend. Otherwise, the request returns an error indicating that autodetect is not supported.

Type: String

Length Constraints: Minimum length of 2. Maximum length of 5.

Required: Yes

TargetLanguageCode

The language code requested for the language of the target text. For a list of language codes, see Supported languages in the Amazon Translate Developer Guide.

Type: String

Length Constraints: Minimum length of 2. Maximum length of 5.

Required: Yes

TerminologyNames

The name of a terminology list file to add to the translation job. This file provides source terms and the desired translation for each term. A terminology list can contain a maximum of 256 terms. You can use one custom terminology resource in your translation request.

Use the ListTerminologies operation to get the available terminology lists.

For more information about custom terminology lists, see Custom terminology in the Amazon Translate Developer Guide.

Type: Array of strings

Length Constraints: Minimum length of 1. Maximum length of 256.

Pattern: ^([A-Za-z0-9-]_?)+$

Required: No

Text

The text to translate. The text string can be a maximum of 10,000 bytes long. Depending on your character set, this may be fewer than 10,000 characters.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 10000.

Pattern: [\P{M}\p{M}]{1,10000}

Required: Yes

Response Syntax

{ "AppliedSettings": { "Brevity": "string", "Formality": "string", "Profanity": "string" }, "AppliedTerminologies": [ { "Name": "string", "Terms": [ { "SourceText": "string", "TargetText": "string" } ] } ], "SourceLanguageCode": "string", "TargetLanguageCode": "string", "TranslatedText": "string" }

Response Elements

If the action is successful, the service sends back an HTTP 200 response.

The following data is returned in JSON format by the service.

AppliedSettings

Optional settings that modify the translation output.

Type: TranslationSettings object

AppliedTerminologies

The names of the custom terminologies applied to the input text by Amazon Translate for the translated text response.

Type: Array of AppliedTerminology objects

SourceLanguageCode

The language code for the language of the source text.

Type: String

Length Constraints: Minimum length of 2. Maximum length of 5.

TargetLanguageCode

The language code for the language of the target text.

Type: String

Length Constraints: Minimum length of 2. Maximum length of 5.

TranslatedText

The translated text.

Type: String

Length Constraints: Maximum length of 20000.

Pattern: [\P{M}\p{M}]{0,20000}

Errors

For information about the errors that are common to all actions, see Common Errors.

DetectedLanguageLowConfidenceException

The confidence that Amazon Comprehend accurately detected the source language is low. If a low confidence level is acceptable for your application, you can use the language in the exception to call Amazon Translate again. For more information, see the DetectDominantLanguage operation in the Amazon Comprehend Developer Guide.

HTTP Status Code: 400

InternalServerException

An internal server error occurred. Retry your request.

HTTP Status Code: 500

InvalidRequestException

The request that you made is not valid. Check your request to determine why it's not valid and then retry the request.

HTTP Status Code: 400

ResourceNotFoundException

The resource you are looking for has not been found. Review the resource you're looking for and see if a different resource will accomplish your needs before retrying the revised request.

HTTP Status Code: 400

ServiceUnavailableException

The Amazon Translate service is temporarily unavailable. Wait a bit and then retry your request.

HTTP Status Code: 500

TextSizeLimitExceededException

The size of the text you submitted exceeds the size limit. Reduce the size of the text or use a smaller document and then retry your request.

HTTP Status Code: 400

TooManyRequestsException

You have made too many requests within a short period of time. Wait for a short time and then try your request again.

HTTP Status Code: 400

UnsupportedLanguagePairException

Amazon Translate does not support translation from the language of the source text into the requested target language. For more information, see Supported languages in the Amazon Translate Developer Guide.

HTTP Status Code: 400

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following: