use of software.amazon.awssdk.services.translate.model.TranslateTextResponse 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 "";
}
Aggregations