How to do it…

The necessary steps include:

  1. Add the following imports to the project:
import java.util.ArrayList;
import java.util.HashMap;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.services.translate.AmazonTranslate;
import com.amazonaws.services.translate.AmazonTranslateClient;
import com.amazonaws.services.translate.model.TranslateTextRequest;
import com.amazonaws.services.translate.model.TranslateTextResult;
  1. Add the following statements to the main method, which will declare the text to be translated:
ArrayList<String> textList = new ArrayList<>();
textList.add("Language is a system that consists of the development, "
+ "acquisition, maintenance and use of complex systems of "
+ "communication, particularly the human ability to do so; "
+ "and a language is any specific example of such a system.");
textList.add("Language ist ein Lied des US-amerikanischen DJs und "
+ "Musikproduzenten Porter Robinson, das von Heather Bright "
+ "gesungen und am 10. April 2012 auf Beatport veröffentlicht"
+ " wurde. Language kann dem Genre Electro House zugeordnet "
+ "werden und hat 128 bpm. Die Vollversion war bereits ab "
+ "dem 26. März 2012 bei YouTube anhörbar. Der Track ist "
+ "unter anderem auch auf dem Soundtrack von Forza Horizon enthalten.");
  1. Follow the previous statements with code to access the Amazon credentials and set up a translation request as follows:
AWSCredentialsProvider awsCredentialsProvider = 
DefaultAWSCredentialsProviderChain.getInstance();
AmazonTranslate amazonTranslate = AmazonTranslateClient.builder()
.withCredentials(awsCredentialsProvider)
.withRegion("us-east-2")
.build();
TranslateTextRequest translateTextRequest = new TranslateTextRequest()
.withText(textList.get(0))
.withSourceLanguageCode("en")
.withTargetLanguageCode("es");
  1. Add the following code to perform the translation and display the results:
TranslateTextResult translateTextResult = 
amazonTranslate.translateText(translateTextRequest);
System.out.println(translateTextResult.getTranslatedText());
System.out.println();
  1. Execute the program. You will get the following output:
El lenguaje es un sistema que consiste en el desarrollo, adquisición, mantenimiento y uso de sistemas complejos de comunicación, en particular la capacidad humana para hacerlo; y un lenguaje es cualquier ejemplo específico de tal sistema.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.5.162