dpebot and dzlier-gcp Auto-update dependencies. (#1178)
* Auto-update dependencies.

* Fix dpebot dependency failures. (#1260)
Latest commit 34e7ecc Nov 15, 2018


Google Cloud Translate Sample

Open in Cloud Shell

This sample demonstrates the use of Google Cloud Translate API for translating and detecting language text.

Java Version

This sample requires you to have Java8.

Download Maven

This sample uses the Apache Maven build system. Before getting started, be sure to download and install it. When you use Maven as described here, it will automatically download the needed client libraries.


This sample uses API Key for authentication.

 API Manager > Credentials > Create credentials > API Key
  • Set the environment variable GOOGLE_API_KEY

Run the sample

To build the sample, we use Maven.

mvn clean compile assembly:single

We can then run the assembled JAR file with the java command. The variable $COMMAND takes three values langsupport, detect and translate.

java -jar $JAR_FILE <detect|translate|langsupport> <text>
    <optional_source> <optional_target>

Example Usage:

INPUT="A quick brown fox jumped over a lazy dog."

Translate API Features:

  • List the languages supported by the API

    java -jar $JAR_FILE langsupport
  • List the languages supported for given target language

    java -jar $JAR_FILE langsupport $TARGET_LANG
  • Detect input text language

    java -jar $JAR_FILE detect "$INPUT"
  • Translate input text (with options)

    java -jar $JAR_FILE translate "$INPUT"
    java -jar $JAR_FILE translate "$INPUT" $SOURCE_LANG $TARGET_LANG