@@ -118,35 +118,18 @@ public List<LanguagesResource> listSupportedLanguages(Map<Option, ?> optionMap)
118118 @ Override
119119 public List <TranslationsResource > translate (List <String > texts , Map <Option , ?> optionMap ) {
120120 try {
121- final String sourceLanguage = SOURCE_LANGUAGE .getString (optionMap );
122- String model = MODEL .getString (optionMap );
123- ImmutableMap .Builder <String , Object > contentBuilder = ImmutableMap .builder ();
124- contentBuilder .put ("target" ,
125- firstNonNull (TARGET_LANGUAGE .getString (optionMap ), options .getTargetLanguage ()));
126- contentBuilder .put ("q" , texts );
127- if (sourceLanguage != null ) {
128- contentBuilder .put ("source" , sourceLanguage );
129- }
130- if (model != null ) {
131- contentBuilder .put ("model" , model );
132- }
133- HttpRequest httpRequest = translate .getRequestFactory ()
134- .buildPostRequest (buildTargetUrl ("" ),
135- new JsonHttpContent (translate .getJsonFactory (), contentBuilder .build ()))
136- .setParser (translate .getObjectParser ());
137- List <TranslationsResource > translations =
138- httpRequest .execute ().parseAs (TranslationsListResponse .class ).getTranslations ();
139- // TODO use REST apiary as soon as it supports POST
140- // String targetLanguage =
141- // firstNonNull(TARGET_LANGUAGE.getString(optionMap), options.getTargetLanguage());
142- // final String sourceLanguage = SOURCE_LANGUAGE.getString(optionMap);
143- // List<TranslationsResource> translations =
144- // translate.translations()
145- // .list(texts, targetLanguage)
146- // .setSource(sourceLanguage)
147- // .setKey(options.getApiKey())
148- // .execute()
149- // .getTranslations();
121+ // TODO use POST as soon as usage of "model" causes error in non-whitelisted projects
122+ String targetLanguage =
123+ firstNonNull (TARGET_LANGUAGE .getString (optionMap ), options .getTargetLanguage ());
124+ final String sourceLanguage = SOURCE_LANGUAGE .getString (optionMap );
125+ List <TranslationsResource > translations =
126+ translate .translations ()
127+ .list (texts , targetLanguage )
128+ .setSource (sourceLanguage )
129+ .setKey (options .getApiKey ())
130+ .set ("model" , MODEL .getString (optionMap ))
131+ .execute ()
132+ .getTranslations ();
150133 return Lists .transform (
151134 translations != null ? translations : ImmutableList .<TranslationsResource >of (),
152135 new Function <TranslationsResource , TranslationsResource >() {
0 commit comments