Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

This project contains a "hello world" translation example.

The pom.xml file defines a main class and some properties that allow us to run via Maven in the command line. The TranslationHelloWorld class fetches the translation of a hard-coded string.

Translate translate = TranslateOptions.getDefaultInstance().getService();

String originalText = "Happy coding!";

Translation translation =
    translate.translate(originalText, TranslateOption.targetLanguage("es"));
String translatedText = translation.getTranslatedText();


To run this example, first make sure your GOOGLE_APPLICATION_CREDENTIALS environment variable is set and that you've enabled the Translation API, and then execute this command:

mvn clean compile exec:java

Learn more at

You can’t perform that action at this time.