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());
}

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 ( ) ) ; }
translate the source text from source to target language .
