How to do it…

The necessary steps include:

  1. Add the following imports to your project:
import java.util.ArrayList;
import java.util.List;
import com.google.cloud.translate.Translate;
import com.google.cloud.translate.TranslateOptions;
import com.google.cloud.translate.Translation;
  1. Add the following statement to the main method. This will create an instance of the Translate class, which will perform the translations:
Translate translate = TranslateOptions.getDefaultInstance().getService();
  1. Add the following code sequence to define a Greek string, perform the translation, and display the result:
String text = "Αυτοκινητόδρομος";
Translation translation = translate.translate(text);
System.out.printf("%-16s Translation: %s ", text, translation.getTranslatedText());
  1. Execute the program. You will get the following output:
Αυτοκινητόδρομος Translation: Highway
..................Content has been hidden....................

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