Search in sources :

Example 6 with TranslateTextRequest

use of software.amazon.awssdk.services.translate.model.TranslateTextRequest in project aws-doc-sdk-examples by awsdocs.

the class LexService method textTranslateFromEn.

public String textTranslateFromEn(String lanCode, String text) {
    Region region = Region.US_EAST_1;
    TranslateClient translateClient = TranslateClient.builder().credentialsProvider(EnvironmentVariableCredentialsProvider.create()).region(region).build();
    try {
        TranslateTextRequest textRequest = TranslateTextRequest.builder().sourceLanguageCode("en").targetLanguageCode(lanCode).text(text).build();
        TranslateTextResponse textResponse = translateClient.translateText(textRequest);
        return textResponse.translatedText();
    } catch (TranslateException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
    return "";
}
Also used : TranslateClient(software.amazon.awssdk.services.translate.TranslateClient) TranslateException(software.amazon.awssdk.services.translate.model.TranslateException) TranslateTextRequest(software.amazon.awssdk.services.translate.model.TranslateTextRequest) Region(software.amazon.awssdk.regions.Region) TranslateTextResponse(software.amazon.awssdk.services.translate.model.TranslateTextResponse)

Aggregations

TranslateTextRequest (software.amazon.awssdk.services.translate.model.TranslateTextRequest)6 TranslateTextResponse (software.amazon.awssdk.services.translate.model.TranslateTextResponse)6 Region (software.amazon.awssdk.regions.Region)5 TranslateClient (software.amazon.awssdk.services.translate.TranslateClient)5 TranslateException (software.amazon.awssdk.services.translate.model.TranslateException)5 SnsClient (software.amazon.awssdk.services.sns.SnsClient)1