本文整理汇总了Java中com.google.cloud.translate.Translate.TranslateOption类的典型用法代码示例。如果您正苦于以下问题:Java TranslateOption类的具体用法?Java TranslateOption怎么用?Java TranslateOption使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TranslateOption类属于com.google.cloud.translate.Translate包,在下文中一共展示了TranslateOption类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: translateText
import com.google.cloud.translate.Translate.TranslateOption; //导入依赖的package包/类
/**
* Translate the source text from source to target language.
*
* @param sourceText source text to be translated
* @param sourceLang source language of the text
* @param targetLang target language of translated text
* @return source text translated into target language.
*/
public static String translateText(
String sourceText,
String sourceLang,
String targetLang) {
if (Strings.isNullOrEmpty(sourceLang)
|| Strings.isNullOrEmpty(targetLang)
|| sourceLang.equals(targetLang)) {
return sourceText;
}
com.google.cloud.translate.Translate translate = createTranslateService();
TranslateOption srcLang = TranslateOption.sourceLanguage(sourceLang);
TranslateOption tgtLang = TranslateOption.targetLanguage(targetLang);
Translation translation = translate.translate(sourceText, srcLang, tgtLang);
return translation.getTranslatedText();
}
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:25,代码来源:Translate.java
示例2: main
import com.google.cloud.translate.Translate.TranslateOption; //导入依赖的package包/类
public static void main(String... args) throws Exception {
// Instantiates a client
Translate translate = TranslateOptions.getDefaultInstance().getService();
// The text to translate
String text = "Hello, world!";
// Translates some text into Russian
Translation translation =
translate.translate(
text,
TranslateOption.sourceLanguage("en"),
TranslateOption.targetLanguage("ru"));
System.out.printf("Text: %s%n", text);
System.out.printf("Translation: %s%n", translation.getTranslatedText());
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:19,代码来源:QuickstartSample.java
示例3: translateTextWithOptionsAndModel
import com.google.cloud.translate.Translate.TranslateOption; //导入依赖的package包/类
/**
* Translate the source text from source to target language.
* Make sure that your project is whitelisted.
*
* @param sourceText source text to be translated
* @param sourceLang source language of the text
* @param targetLang target language of translated text
* @param out print stream
*/
public static void translateTextWithOptionsAndModel(
String sourceText,
String sourceLang,
String targetLang,
PrintStream out) {
Translate translate = createTranslateService();
TranslateOption srcLang = TranslateOption.sourceLanguage(sourceLang);
TranslateOption tgtLang = TranslateOption.targetLanguage(targetLang);
// Use translate `model` parameter with `base` and `nmt` options.
TranslateOption model = TranslateOption.model("nmt");
Translation translation = translate.translate(sourceText, srcLang, tgtLang, model);
out.printf("Source Text:\n\tLang: %s, Text: %s\n", sourceLang, sourceText);
out.printf("TranslatedText:\n\tLang: %s, Text: %s\n", targetLang,
translation.getTranslatedText());
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:28,代码来源:TranslateText.java
示例4: translateTextWithOptions
import com.google.cloud.translate.Translate.TranslateOption; //导入依赖的package包/类
/**
* Translate the source text from source to target language.
*
* @param sourceText source text to be translated
* @param sourceLang source language of the text
* @param targetLang target language of translated text
* @param out print stream
*/
public static void translateTextWithOptions(
String sourceText,
String sourceLang,
String targetLang,
PrintStream out) {
Translate translate = createTranslateService();
TranslateOption srcLang = TranslateOption.sourceLanguage(sourceLang);
TranslateOption tgtLang = TranslateOption.targetLanguage(targetLang);
Translation translation = translate.translate(sourceText, srcLang, tgtLang);
out.printf("Source Text:\n\tLang: %s, Text: %s\n", sourceLang, sourceText);
out.printf("TranslatedText:\n\tLang: %s, Text: %s\n", targetLang,
translation.getTranslatedText());
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:24,代码来源:TranslateText.java
示例5: GoogleTranslateApiPageOutput
import com.google.cloud.translate.Translate.TranslateOption; //导入依赖的package包/类
public GoogleTranslateApiPageOutput(TaskSource taskSource, Schema inputSchema, Schema outputSchema, PageOutput output) {
this.task = taskSource.loadTask(PluginTask.class);
this.outputSchema = outputSchema;
this.inputColumns = inputSchema.getColumns();
this.reader = new PageReader(inputSchema);
this.builder = new PageBuilder(Exec.getBufferAllocator(), outputSchema, output);
this.keyNameColumns = Lists.newArrayList();
for (String keyName : task.getKeyNames()) {
this.keyNameColumns.add(outputSchema.lookupColumn(keyName));
}
this.translate = createTranslateService();
this.srcLang = task.getSourceLang().isPresent() ? TranslateOption.sourceLanguage(task.getSourceLang().get()) : null;
this.model = task.getModel().isPresent() ? TranslateOption.model(task.getModel().get()) : null;
}
开发者ID:toyama0919,项目名称:embulk-filter-google_translate_api,代码行数:16,代码来源:GoogleTranslateApiPageOutput.java
示例6: translate
import com.google.cloud.translate.Translate.TranslateOption; //导入依赖的package包/类
/**
* @param texts
* @return
*/
private List<Translation> translate(List<String> texts) {
TranslateOption[] translateOptions = new TranslateOption[] {};
if (srcLang != null) {
translateOptions = ArrayUtils.add(translateOptions, srcLang);
}
if (model != null) {
translateOptions = ArrayUtils.add(translateOptions, model);
}
return translate.translate(texts, translateOptions);
}
开发者ID:toyama0919,项目名称:embulk-filter-google_translate_api,代码行数:15,代码来源:GoogleTranslateApiPageOutput.java
示例7: translate
import com.google.cloud.translate.Translate.TranslateOption; //导入依赖的package包/类
public String translate(String text, String languageFrom,
String languageTo) {
Translation translation = translate.translate(text,
TranslateOption.sourceLanguage(languageFrom),
TranslateOption.targetLanguage(languageTo));
String translatedText = translation.getTranslatedText();
log.trace("Translating {} [{}] to [{}] ... result={}", text,
languageFrom, languageTo, translatedText);
return translatedText;
}
开发者ID:bonigarcia,项目名称:dualsub,代码行数:12,代码来源:Translator.java
注:本文中的com.google.cloud.translate.Translate.TranslateOption类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论