GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — java-docs-samples/translate at master · rDarge/java-docs-samples

Expand file tree

/

translate

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
 
 
/

translate

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
cloud-client
cloud-client
 
 
src
src
 
 
README.md
README.md
 
 
pom.xml
pom.xml
 
 

README.md

Outline

Google Cloud Translate Sample

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.

Authentication

This sample uses API Key for authentication.

  • Visit the Google Cloud Console and navigate to:
 API Manager > Credentials > Create credentials > API Key
  • Set the environment variable GOOGLE_API_KEY
 export GOOGLE_API_KEY=<YOUR_PROJECT_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.

JAR_FILE=target/translate-1.0-jar-with-dependencies.jar
java -jar $JAR_FILE <detect|translate|langsupport> <text>
    <optional_source> <optional_target>

Example Usage:

INPUT="A quick brown fox jumped over a lazy dog."
SOURCE_LANG="en"
TARGET_LANG="fr"

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

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.