[Google Translation API v2 for Java]

Reference:
https://cloud.google.com/translate/docs/reference/libraries#java-resources

QuickstartSample:
 1 // Imports the Google Cloud client library
 2 import com.google.cloud.translate.Translate;
 3 import com.google.cloud.translate.Translate.TranslateOption;
 4 import com.google.cloud.translate.TranslateOptions;
 5 import com.google.cloud.translate.Translation;
 6 
 7 public class QuickstartSample {
 8   public static void main(String... args) throws Exception {
 9     // Instantiates a client
10     Translate translate = TranslateOptions.builder().apiKey("YOUR_API_KEY").build().service();
11 
12     // The text to translate
13     String text = "Hello, world!";
14 
15     // Translates some text into Russian
16     Translation translation = translate.translate(
17       text,
18       TranslateOption.sourceLanguage("en"),
19       TranslateOption.targetLanguage("ru")
20     );
21 
22     System.out.printf("Text: %s%n", text);
23     System.out.printf("Translation: %s%n", translation.translatedText());
24   }
25 }

 

maven:

1 <dependency>
2     <groupId>com.google.cloud</groupId>
3     <artifactId>google-cloud-translate</artifactId>
4     <version>0.4.0</version>
5 </dependency>

 

 
posted @ 2016-10-13 09:37  max_xbw  阅读(603)  评论(0编辑  收藏  举报