translateText method
Translates input text from the source language to the target language. For a list of available languages and language codes, see what-is-languages.
May throw InvalidRequestException. May throw TextSizeLimitExceededException. May throw TooManyRequestsException. May throw UnsupportedLanguagePairException. May throw DetectedLanguageLowConfidenceException. May throw ResourceNotFoundException. May throw InternalServerException. May throw ServiceUnavailableException.
Parameter sourceLanguageCode
:
The language code for the language of the source text. The language must
be a language supported by Amazon Translate. For a list of language codes,
see what-is-languages.
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.
Parameter targetLanguageCode
:
The language code requested for the language of the target text. The
language must be a language supported by Amazon Translate.
Parameter text
:
The text to translate. The text string can be a maximum of 5,000 bytes
long. Depending on your character set, this may be fewer than 5,000
characters.
Parameter terminologyNames
:
The name of the terminology list file to be used in the TranslateText
request. You can use 1 terminology list at most in a
TranslateText
request. Terminology lists can contain a
maximum of 256 terms.
Implementation
Future<TranslateTextResponse> translateText({
required String sourceLanguageCode,
required String targetLanguageCode,
required String text,
List<String>? terminologyNames,
}) async {
ArgumentError.checkNotNull(sourceLanguageCode, 'sourceLanguageCode');
_s.validateStringLength(
'sourceLanguageCode',
sourceLanguageCode,
2,
5,
isRequired: true,
);
ArgumentError.checkNotNull(targetLanguageCode, 'targetLanguageCode');
_s.validateStringLength(
'targetLanguageCode',
targetLanguageCode,
2,
5,
isRequired: true,
);
ArgumentError.checkNotNull(text, 'text');
_s.validateStringLength(
'text',
text,
1,
5000,
isRequired: true,
);
final headers = <String, String>{
'Content-Type': 'application/x-amz-json-1.1',
'X-Amz-Target': 'AWSShineFrontendService_20170701.TranslateText'
};
final jsonResponse = await _protocol.send(
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
// TODO queryParams
headers: headers,
payload: {
'SourceLanguageCode': sourceLanguageCode,
'TargetLanguageCode': targetLanguageCode,
'Text': text,
if (terminologyNames != null) 'TerminologyNames': terminologyNames,
},
);
return TranslateTextResponse.fromJson(jsonResponse.body);
}