use of software.amazon.awssdk.services.translate.model.TranslateTextResponse in project aws-doc-sdk-examples by awsdocs.
the class RetrieveDataRDS method translateText.
private String translateText(String text, String lang) {
Region region = Region.US_WEST_2;
TranslateClient translateClient = TranslateClient.builder().credentialsProvider(EnvironmentVariableCredentialsProvider.create()).region(region).build();
String transValue = "";
try {
if (lang.compareTo("French") == 0) {
TranslateTextRequest textRequest = TranslateTextRequest.builder().sourceLanguageCode("en").targetLanguageCode("fr").text(text).build();
TranslateTextResponse textResponse = translateClient.translateText(textRequest);
transValue = textResponse.translatedText();
} else if (lang.compareTo("Russian") == 0) {
TranslateTextRequest textRequest = TranslateTextRequest.builder().sourceLanguageCode("en").targetLanguageCode("ru").text(text).build();
TranslateTextResponse textResponse = translateClient.translateText(textRequest);
transValue = textResponse.translatedText();
} else if (lang.compareTo("Japanese") == 0) {
TranslateTextRequest textRequest = TranslateTextRequest.builder().sourceLanguageCode("en").targetLanguageCode("ja").text(text).build();
TranslateTextResponse textResponse = translateClient.translateText(textRequest);
transValue = textResponse.translatedText();
} else if (lang.compareTo("Spanish") == 0) {
TranslateTextRequest textRequest = TranslateTextRequest.builder().sourceLanguageCode("en").targetLanguageCode("es").text(text).build();
TranslateTextResponse textResponse = translateClient.translateText(textRequest);
transValue = textResponse.translatedText();
} else {
TranslateTextRequest textRequest = TranslateTextRequest.builder().sourceLanguageCode("en").targetLanguageCode("zh").text(text).build();
TranslateTextResponse textResponse = translateClient.translateText(textRequest);
transValue = textResponse.translatedText();
}
return transValue;
} catch (TranslateException e) {
System.err.println(e.getMessage());
System.exit(1);
}
return "";
}
use of software.amazon.awssdk.services.translate.model.TranslateTextResponse in project aws-doc-sdk-examples by awsdocs.
the class RedshiftService method translateText.
private String translateText(String text, String lang) {
Region region = Region.US_WEST_2;
TranslateClient translateClient = TranslateClient.builder().credentialsProvider(EnvironmentVariableCredentialsProvider.create()).region(region).build();
String transValue = "";
try {
if (lang.compareTo("French") == 0) {
TranslateTextRequest textRequest = TranslateTextRequest.builder().sourceLanguageCode("en").targetLanguageCode("fr").text(text).build();
TranslateTextResponse textResponse = translateClient.translateText(textRequest);
transValue = textResponse.translatedText();
} else if (lang.compareTo("Russian") == 0) {
TranslateTextRequest textRequest = TranslateTextRequest.builder().sourceLanguageCode("en").targetLanguageCode("ru").text(text).build();
TranslateTextResponse textResponse = translateClient.translateText(textRequest);
transValue = textResponse.translatedText();
} else if (lang.compareTo("Japanese") == 0) {
TranslateTextRequest textRequest = TranslateTextRequest.builder().sourceLanguageCode("en").targetLanguageCode("ja").text(text).build();
TranslateTextResponse textResponse = translateClient.translateText(textRequest);
transValue = textResponse.translatedText();
} else if (lang.compareTo("Spanish") == 0) {
TranslateTextRequest textRequest = TranslateTextRequest.builder().sourceLanguageCode("en").targetLanguageCode("es").text(text).build();
TranslateTextResponse textResponse = translateClient.translateText(textRequest);
transValue = textResponse.translatedText();
} else {
TranslateTextRequest textRequest = TranslateTextRequest.builder().sourceLanguageCode("en").targetLanguageCode("zh").text(text).build();
TranslateTextResponse textResponse = translateClient.translateText(textRequest);
transValue = textResponse.translatedText();
}
return transValue;
} catch (TranslateException e) {
System.err.println(e.getMessage());
System.exit(1);
}
return "";
}
use of software.amazon.awssdk.services.translate.model.TranslateTextResponse in project aws-doc-sdk-examples by awsdocs.
the class SnsService method pubTopic.
public String pubTopic(String message, String lang) {
try {
String body;
Region region = Region.US_WEST_2;
TranslateClient translateClient = TranslateClient.builder().credentialsProvider(EnvironmentVariableCredentialsProvider.create()).region(region).build();
if (lang.compareTo("English") == 0) {
body = message;
} else if (lang.compareTo("French") == 0) {
TranslateTextRequest textRequest = TranslateTextRequest.builder().sourceLanguageCode("en").targetLanguageCode("fr").text(message).build();
TranslateTextResponse textResponse = translateClient.translateText(textRequest);
body = textResponse.translatedText();
} else {
TranslateTextRequest textRequest = TranslateTextRequest.builder().sourceLanguageCode("en").targetLanguageCode("es").text(message).build();
TranslateTextResponse textResponse = translateClient.translateText(textRequest);
body = textResponse.translatedText();
}
SnsClient snsClient = getSnsClient();
PublishRequest request = PublishRequest.builder().message(body).topicArn(topicArn).build();
PublishResponse result = snsClient.publish(request);
return " Message sent in " + lang + ". Status was " + result.sdkHttpResponse().statusCode();
} catch (SnsException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
return "Error - msg not sent";
}
use of software.amazon.awssdk.services.translate.model.TranslateTextResponse in project aws-doc-sdk-examples by awsdocs.
the class TranslateText method textTranslate.
// snippet-start:[translate.java2._text.main]
public static void textTranslate(TranslateClient translateClient) {
try {
TranslateTextRequest textRequest = TranslateTextRequest.builder().sourceLanguageCode("en").targetLanguageCode("fr").text("Its a sunny day today").build();
TranslateTextResponse textResponse = translateClient.translateText(textRequest);
System.out.println(textResponse.translatedText());
} catch (TranslateException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.translate.model.TranslateTextResponse in project aws-doc-sdk-examples by awsdocs.
the class LexService method textTranslateToEn.
public String textTranslateToEn(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(lanCode).targetLanguageCode("en").text(text).build();
TranslateTextResponse textResponse = translateClient.translateText(textRequest);
return textResponse.translatedText();
} catch (TranslateException e) {
System.err.println(e.getMessage());
System.exit(1);
}
return "";
}
Aggregations