use of com.google.cloud.translate.Detection in project google-cloud-java by GoogleCloudPlatform.
the class ITTranslateTest method testDetectLanguageOfText.
@Test
public void testDetectLanguageOfText() {
Detection detection = TRANSLATE.detect("Hello");
assertEquals("en", detection.getLanguage());
}
use of com.google.cloud.translate.Detection in project google-cloud-java by GoogleCloudPlatform.
the class ITTranslateTest method testDetectLanguageOfTextList.
@Test
public void testDetectLanguageOfTextList() {
List<Detection> detections = TRANSLATE.detect(ImmutableList.of("Hello", "Hallo"));
Detection detection = detections.get(0);
assertEquals("en", detection.getLanguage());
detection = detections.get(1);
assertEquals("de", detection.getLanguage());
}
use of com.google.cloud.translate.Detection in project google-cloud-java by GoogleCloudPlatform.
the class ITTranslateTest method testDetectLanguageOfTexts.
@Test
public void testDetectLanguageOfTexts() {
List<Detection> detections = TRANSLATE.detect("Hello", "Hallo");
Detection detection = detections.get(0);
assertEquals("en", detection.getLanguage());
detection = detections.get(1);
assertEquals("de", detection.getLanguage());
}
use of com.google.cloud.translate.Detection in project java-docs-samples by GoogleCloudPlatform.
the class TranslateText method detectLanguage.
/**
* Detect the language of input text.
*
* @param sourceText source text to be detected for language
* @param out print stream
*/
public static void detectLanguage(String sourceText, PrintStream out) {
Translate translate = createTranslateService();
List<Detection> detections = translate.detect(ImmutableList.of(sourceText));
System.out.println("Language(s) detected:");
for (Detection detection : detections) {
out.printf("\t%s\n", detection);
}
}
use of com.google.cloud.translate.Detection in project google-cloud-java by GoogleCloudPlatform.
the class ITTranslateSnippets method testDetectLanguageOfTexts.
@Test
public void testDetectLanguageOfTexts() {
// SNIPPET translate_detect_language_array
List<Detection> detections = translate.detect("Hello, World!", "¡Hola Mundo!");
// SNIPPET translate_detect_language_array
Detection detection = detections.get(0);
assertEquals("en", detection.getLanguage());
detection = detections.get(1);
assertEquals("es", detection.getLanguage());
}
Aggregations