11/**
22 * Copyright 2015 IBM Corp. All Rights Reserved.
3- *
3+ *
44 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
55 * in compliance with the License. You may obtain a copy of the License at
6- *
6+ *
77 * http://www.apache.org/licenses/LICENSE-2.0
8- *
8+ *
99 * Unless required by applicable law or agreed to in writing, software distributed under the License
1010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
1111 * or implied. See the License for the specific language governing permissions and limitations under
2424import com .ibm .watson .developer_cloud .language_translation .v2 .model .CreateModelOptions ;
2525import com .ibm .watson .developer_cloud .language_translation .v2 .model .IdentifiableLanguage ;
2626import com .ibm .watson .developer_cloud .language_translation .v2 .model .IdentifiedLanguage ;
27+ import com .ibm .watson .developer_cloud .language_translation .v2 .model .Language ;
2728import com .ibm .watson .developer_cloud .language_translation .v2 .model .LanguageList ;
2829import com .ibm .watson .developer_cloud .language_translation .v2 .model .TranslationModel ;
2930import com .ibm .watson .developer_cloud .language_translation .v2 .model .TranslationModelList ;
3738/**
3839 * The IBM Watson Language Translation service translate text from one language to another and
3940 * identifies the language in which text is written.
40- *
41+ *
4142 * @version v2
4243 * @see <a href=
4344 * "http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/language-translation.html">
@@ -92,7 +93,7 @@ public LanguageTranslation() {
9293
9394 /**
9495 * Creates a translation models.
95- *
96+ *
9697 * @param options the create model options
9798 * @return the translation model
9899 */
@@ -125,7 +126,7 @@ public TranslationModel createModel(CreateModelOptions options) {
125126
126127 /**
127128 * Deletes a translation models.
128- *
129+ *
129130 * @param modelId the model identifier
130131 */
131132 public void deleteModel (String modelId ) {
@@ -138,7 +139,7 @@ public void deleteModel(String modelId) {
138139
139140 /**
140141 * Retrieves the list of identifiable languages.
141- *
142+ *
142143 * @return the identifiable languages
143144 * @see TranslationModel
144145 */
@@ -150,7 +151,7 @@ public List<IdentifiableLanguage> getIdentifiableLanguages() {
150151
151152 /**
152153 * Retrieves a translation models.
153- *
154+ *
154155 * @param modelId the model identifier
155156 * @return the translation models
156157 * @see TranslationModel
@@ -165,7 +166,7 @@ public TranslationModel getModel(String modelId) {
165166
166167 /**
167168 * Retrieves the list of translation models.
168- *
169+ *
169170 * @return the translation models
170171 * @see TranslationModel
171172 */
@@ -175,7 +176,7 @@ public List<TranslationModel> getModels() {
175176
176177 /**
177178 * Retrieves the list of models.
178- *
179+ *
179180 * @param showDefault show default models
180181 * @param source the source
181182 * @param target the target
@@ -202,7 +203,7 @@ public List<TranslationModel> getModels(final Boolean showDefault, final String
202203
203204 /**
204205 * Identify language in which text is written.
205- *
206+ *
206207 * @param text the text to identify
207208 * @return the identified language
208209 */
@@ -219,7 +220,7 @@ public List<IdentifiedLanguage> identify(final String text) {
219220
220221 /**
221222 * Translate text using a model.
222- *
223+ *
223224 * @param text The submitted paragraphs to translate
224225 * @param modelId the model id
225226 * @return The {@link TranslationResult}
@@ -233,32 +234,32 @@ public TranslationResult translate(final String text, final String modelId) {
233234 * Translate text using source and target languages.<br>
234235 * <br>
235236 * Here is an example of how to translate "hello" from English to Spanish:
236- *
237- *
237+ *
238+ *
238239 * <pre>
239240 * LanguageTranslation service = new LanguageTranslation();
240241 * service.setUsernameAndPassword("USERNAME", "PASSWORD");
241- *
242+ *
242243 * TranslationResult translationResult = service.translate("hello", "en", "es");
243- *
244+ *
244245 * System.out.println(translationResult);
245246 * </pre>
246- *
247+ *
247248 * @param text The submitted paragraphs to translate
248249 * @param source The source language
249250 * @param target The target language
250251 * @return The {@link TranslationResult}
251252 */
252- public TranslationResult translate (final String text , final String source , final String target ) {
253- Validate .isTrue (source != null && ! source . isEmpty () , "source cannot be null or empty " );
254- Validate .isTrue (target != null && ! target . isEmpty () , "target cannot be null or empty " );
255- return translateRequest (text , null , source , target );
253+ public TranslationResult translate (final String text , final Language source , final Language target ) {
254+ Validate .isTrue (source != null , "source cannot be null" );
255+ Validate .isTrue (target != null , "target cannot be null" );
256+ return translateRequest (text , null , source . toString () , target . toString () );
256257 }
257258
258259 /**
259260 * Translate paragraphs of text using a model and or source and target. model_id or source and
260261 * target needs to be specified. If both are specified, then only model_id will be used
261- *
262+ *
262263 * @param text the text
263264 * @param modelId the model id
264265 * @param source the source
0 commit comments