From 704264fd77d9354aba630e3411eeda7261233fdf Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Tue, 15 Nov 2016 12:11:48 -0800 Subject: [PATCH] added function without and with model --- .../translate/samples/TranslateText.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/translate/src/main/java/com/google/cloud/translate/samples/TranslateText.java b/translate/src/main/java/com/google/cloud/translate/samples/TranslateText.java index 823ead3a37d..85888e84738 100644 --- a/translate/src/main/java/com/google/cloud/translate/samples/TranslateText.java +++ b/translate/src/main/java/com/google/cloud/translate/samples/TranslateText.java @@ -61,13 +61,14 @@ public static void translateText(String sourceText, PrintStream out) { /** * 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 translateTextWithOptions( + public static void translateTextWithOptionsAndModel( String sourceText, String sourceLang, String targetLang, @@ -85,6 +86,30 @@ public static void translateTextWithOptions( out.printf("TranslatedText:\n\tLang: %s, Text: %s\n", targetLang, translation.translatedText()); } + + /** + * 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.translatedText()); + } + /** * Displays a list of supported languages and codes. *