/** * Translates an array of texts from a given Language to another given Language using Microsoft Translator's TranslateArray * service * * Note that the Microsoft Translator expects all source texts to be of the SAME language. * * @param texts The Strings Array to translate. * @param from The language code to translate from. * @param to The language code to translate to. * @return The translated Strings Array[]. * @throws Exception on error. */ public static String[] execute(final String[] texts, final Language from, final Language to) throws Exception { //Run the basic service validations first validateServiceState(texts); final String params = (apiKey != null ? PARAM_APP_ID + URLEncoder.encode(apiKey,ENCODING) : "") + PARAM_FROM_LANG + URLEncoder.encode(from.toString(),ENCODING) + PARAM_TO_LANG + URLEncoder.encode(to.toString(),ENCODING) + PARAM_TEXT_ARRAY + URLEncoder.encode(buildStringArrayParam(texts),ENCODING); final URL url = new URL(ARRAY_SERVICE_URL + params); final String[] response = retrieveStringArr(url,ARRAY_JSON_OBJECT_PROPERTY); return response; }
/** * Translates an array of texts from a given Language to another given Language using Microsoft Translator's TranslateArray * service * * Note that the Microsoft Translator expects all source texts to be of the SAME language. * * @param texts The Strings Array to translate. * @param from The language code to translate from. * @param to The language code to translate to. * @return The translated Strings Array[]. * @throws Exception on error. */ public static String[] execute(final String[] texts, final Language from, final Language to) throws Exception { //Run the basic service validations first validateServiceState(texts); final String params = (apiKey != null ? PARAM_APP_ID + URLEncoder.encode(apiKey,ENCODING) : "") + PARAM_FROM_LANG + URLEncoder.encode(from.toString(),ENCODING) + PARAM_TO_LANG + URLEncoder.encode(to.toString(),ENCODING) + PARAM_TEXT_ARRAY + URLEncoder.encode(buildStringArrayParam(texts),ENCODING); final URL url = new URL(ARRAY_SERVICE_URL + params); final String[] response = retrieveStringArr(url,ARRAY_JSON_OBJECT_PROPERTY); return response; }