@Override public List<List<DetectionsResourceItems>> detect(List<String> texts) { try { List<List<DetectionsResourceItems>> detections = translate.detections().list(texts).setKey(options.apiKey()).execute().getDetections(); return detections != null ? detections : ImmutableList.<List<DetectionsResourceItems>>of(); } catch (IOException ex) { throw translate(ex); } }
@Override public List<LanguagesResource> listSupportedLanguages(Map<Option, ?> optionMap) { try { List<LanguagesResource> languages = translate.languages() .list() .setKey(options.apiKey()) .setTarget(firstNonNull(TARGET_LANGUAGE.getString(optionMap), options.targetLanguage())) .execute().getLanguages(); return languages != null ? languages : ImmutableList.<LanguagesResource>of(); } catch (IOException ex) { throw translate(ex); } }
@Override public List<TranslationsResource> translate(List<String> texts, Map<Option, ?> optionMap) { try { String targetLanguage = firstNonNull(TARGET_LANGUAGE.getString(optionMap), options.targetLanguage()); final String sourceLanguage = SOURCE_LANGUAGE.getString(optionMap); List<TranslationsResource> translations = translate.translations() .list(texts, targetLanguage) .setSource(sourceLanguage) .setKey(options.apiKey()) .execute() .getTranslations(); return Lists.transform( translations != null ? translations : ImmutableList.<TranslationsResource>of(), new Function<TranslationsResource, TranslationsResource>() { @Override public TranslationsResource apply(TranslationsResource translationsResource) { if (translationsResource.getDetectedSourceLanguage() == null) { translationsResource.setDetectedSourceLanguage(sourceLanguage); } return translationsResource; } }); } catch (IOException ex) { throw translate(ex); } } }