I created a new translation connector in AEM for doing machine translation. The translation works fine without any issue. The challenge I am having is to set translation status when there is an issue in vendor translation.
public class TranslationServiceImpl extends AbstractTranslationService implements TranslationService {
public TranslationResult translateString(String sourceString, String sourceLanguage, String targetLanguage,
TranslationConstants.ContentType contentType, String contentCategory, String jobID) throws TranslationException {
LOG.debug("translateString is called");
String translatedString = null; // Initialize to null to check later
try {
translatedString = tmsService.getTranslatedText(sourceString, this.configMap, sourceLanguage, targetLanguage, jobID);
} catch (KeyManagementException | UnsupportedOperationException | NoSuchAlgorithmException
| KeyStoreException | IOException | InterruptedException e) {
LOG.error("Exception occurred during translation", e);
throw new TranslationException("Translation is failed", TranslationException.ErrorCode.TRANSLATION_FAILED);
}
if (translatedString == null) {
LOG.error("Translation failed: translatedString is null");
throw new TranslationException("Translation is failed", TranslationException.ErrorCode.TRANSLATION_FAILED);
}
return new TranslationResultImpl(translatedString, sourceLanguage, targetLanguage, contentType,
contentCategory, sourceString, TranslationResultImpl.UNKNOWN_RATING, null);
}
@Override
public TranslationStatus getTranslationObjectStatus(String strTranslationJobID,
TranslationObject translationObject) throws TranslationException {
LOG.debug("getTranslationObjectStatus is called");
LOG.debug("strTranslationJobID -->"+strTranslationJobID);
LOG.debug("translationObject -->"+translationObject.getTitle());
//throw new TranslationException("This function is not implemented", TranslationException.ErrorCode.SERVICE_NOT_IMPLEMENTED);
return TranslationStatus.ERROR_UPDATE;
}
@Override
public void storeTranslation(String[] originalText, String sourceLanguage, String targetLanguage,
String[] updatedTranslation, ContentType contentType, String contentCategory,
String userId, int rating, String path) throws TranslationException {
LOG.debug("storeTranslation");
throw new TranslationException("Not implemented", TranslationException.ErrorCode.SERVICE_NOT_IMPLEMENTED); // update this based on condition
}
// other methods
}
I am setting TranslationException.ErrorCode.TRANSLATION_FAILED if there is any error during translation but I see it is always Approved status.
I also tried to explore if I can do anything on the getTranslationObjectStatus method but this method is never invoked. Any idea why it is not invoked ?