@@ -61,13 +61,14 @@ public static void translateText(String sourceText, PrintStream out) {
61
61
62
62
/**
63
63
* Translate the source text from source to target language.
64
+ * Make sure that your project is whitelisted.
64
65
*
65
66
* @param sourceText source text to be translated
66
67
* @param sourceLang source language of the text
67
68
* @param targetLang target language of translated text
68
69
* @param out print stream
69
70
*/
70
- public static void translateTextWithOptions (
71
+ public static void translateTextWithOptionsAndModel (
71
72
String sourceText ,
72
73
String sourceLang ,
73
74
String targetLang ,
@@ -85,6 +86,30 @@ public static void translateTextWithOptions(
85
86
out .printf ("TranslatedText:\n \t Lang: %s, Text: %s\n " , targetLang , translation .translatedText ());
86
87
}
87
88
89
+
90
+ /**
91
+ * Translate the source text from source to target language.
92
+ *
93
+ * @param sourceText source text to be translated
94
+ * @param sourceLang source language of the text
95
+ * @param targetLang target language of translated text
96
+ * @param out print stream
97
+ */
98
+ public static void translateTextWithOptions (
99
+ String sourceText ,
100
+ String sourceLang ,
101
+ String targetLang ,
102
+ PrintStream out ) {
103
+
104
+ Translate translate = createTranslateService ();
105
+ TranslateOption srcLang = TranslateOption .sourceLanguage (sourceLang );
106
+ TranslateOption tgtLang = TranslateOption .targetLanguage (targetLang );
107
+
108
+ Translation translation = translate .translate (sourceText , srcLang , tgtLang );
109
+ out .printf ("Source Text:\n \t Lang: %s, Text: %s\n " , sourceLang , sourceText );
110
+ out .printf ("TranslatedText:\n \t Lang: %s, Text: %s\n " , targetLang , translation .translatedText ());
111
+ }
112
+
88
113
/**
89
114
* Displays a list of supported languages and codes.
90
115
*
0 commit comments