} catch (Throwable ex) {
LOGGER.warn("Could not detect language", ex);
return;
}
ExistingElementMutation m = data.getElement().prepareMutation()
.alterPropertyMetadata(data.getProperty(), LumifyProperties.META_DATA_LANGUAGE, language);
boolean translated = false;
String translatedTextPropertyKey = data.getProperty().getKey() + "#en";
if (!language.equals("en") && !hasTranslatedProperty(data, translatedTextPropertyKey)) {
LOGGER.debug("translating text of property: %s", data.getProperty().toString());
String translatedText = translator.translate(text, language, data);
if (translatedText != null && translatedText.length() > 0) {
Object translatedTextValue;
if (data.getProperty().getValue() instanceof StreamingPropertyValue) {
translatedTextValue = new StreamingPropertyValue(new ByteArrayInputStream(translatedText.getBytes()), String.class);
} else {
translatedTextValue = translatedText;
}
Map<String, Object> metadata = data.createPropertyMetadata();
metadata.put(LumifyProperties.META_DATA_LANGUAGE, "en");
String description = (String) data.getProperty().getMetadata().get(LumifyProperties.META_DATA_TEXT_DESCRIPTION);
if (description == null || description.length() == 0) {
description = "Text";
}
metadata.put(LumifyProperties.META_DATA_TEXT_DESCRIPTION, description + " (en)");
metadata.put(LumifyProperties.META_DATA_MIME_TYPE, "text/plain");
m.addPropertyValue(translatedTextPropertyKey, data.getProperty().getName(), translatedTextValue, metadata, data.getProperty().getVisibility());
translated = true;
}
}
m.save(getAuthorizations());
if (translated) {
getGraph().flush();
getWorkQueueRepository().pushGraphPropertyQueue(data.getElement(), translatedTextPropertyKey, data.getProperty().getName(), data.getWorkspaceId(), data.getVisibilitySource());
}