Skip navigation links

Package com.google.cloud.translate

A client for Cloud Translation - Fast, dynamic translation.

See: Description

Package com.google.cloud.translate Description

A client for Cloud Translation - Fast, dynamic translation.

Here's a simple usage example for Google Cloud Translation. This example shows how to detect the language of some text and how to translate some text. The example assumes that either Application Default Credentials are available or that the GOOGLE_API_KEY environment variable is set and contains a valid API key. Alternatively, you can use setCredentials to set credentials, or TranslateOptions.Builder.setApiKey(java.lang.String) to set an API key. For the complete source code see DetectLanguageAndTranslate.java.

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

 Detection detection = translate.detect("Hola");
 String detectedLanguage = detection.getLanguage();

 Translation translation = translate.translate(
     "World",
     TranslateOption.sourceLanguage("en"),
     TranslateOption.targetLanguage(detectedLanguage));

 System.out.printf("Hola %s%n", translation.getTranslatedText());
 
Skip navigation links

Copyright © 2022 Google LLC. All rights reserved.