XBWer
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>

 

 

分类:

技术点:

相关文章:

  • 2021-11-08
  • 2021-06-01
  • 2021-04-04
  • 2021-06-25
  • 2021-10-09
  • 2021-06-23
  • 2021-09-07
  • 2021-09-06
猜你喜欢
  • 2021-12-23
  • 2022-01-17
  • 2021-09-18
  • 2021-12-03
  • 2021-10-15
  • 2021-07-28
  • 2022-01-08
相关资源
相似解决方案