Skip to content

Commit

Permalink
Merge pull request #414 from GoogleCloudPlatform/without_model_translate
Browse files Browse the repository at this point in the history
added function without and with model
  • Loading branch information
puneith authored Nov 15, 2016
2 parents a3dcbaf + 704264f commit 0b783b7
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
*
Expand Down

0 comments on commit 0b783b7

Please sign in to comment.