use of software.amazon.awssdk.services.translate.TranslateClient 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.TranslateClient in project aws-doc-sdk-examples by awsdocs.
the class DescribeTextTranslationJob method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage:\n" + " <id> \n\n" + "Where:\n" + " id - a translation job ID value. You can obtain this value from the BatchTranslation example.\n";
if (args.length != 1) {
System.out.println(USAGE);
System.exit(1);
}
String id = args[0];
Region region = Region.US_WEST_2;
TranslateClient translateClient = TranslateClient.builder().region(region).build();
describeTextTranslationJob(translateClient, id);
translateClient.close();
}
use of software.amazon.awssdk.services.translate.TranslateClient 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.TranslateClient 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.TranslateClient in project aws-doc-sdk-examples by awsdocs.
the class TranslateText method main.
public static void main(String[] args) {
Region region = Region.US_WEST_2;
TranslateClient translateClient = TranslateClient.builder().credentialsProvider(EnvironmentVariableCredentialsProvider.create()).region(region).build();
textTranslate(translateClient);
translateClient.close();
}
Aggregations