• [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>
     
  • 相关阅读:
    08day 操作命令以及目录结构
    换工作
    json转为字典
    快速排序
    冒泡排序
    python函数-生成器
    关键字global
    函数的定义和参数调用
    count()函数与center()函数
    python字符串常用函数:strip()
  • 原文地址:https://www.cnblogs.com/XBWer/p/5955246.html
Copyright © 2020-2023  润新知