Interface ITranslator
- All Known Subinterfaces:
IEditorTranslator
- All Known Implementing Classes:
AzureCognitiveServices, AzureCognitiveServices, AzureCognitiveServicesTest, GoogleTranslate, GoogleTranslate, TestGoogleTranslate
public interface ITranslator
The translator interface.
- Author:
- Christopher Mindus
Method Summary
Modifier and TypeMethodDescriptionbooleancanTranslate(String sourceLanguageCode, String targetLanguageCode) Checks if a translation is handled between two language codes.voidDeconfigures the translator to "lose" the API key(s).getLanguageCode(String languageCode) Gets the "real" language code, no matter the input case.getLanguageDescription(String languageCode) Gets the language description for a language code, e.g.getName()Returns the name of this translator.Gets the ready state of this translator.booleanisLanguageHandled(String languageCode) Verifies if a Language Code is handled by this translator.Translates a text in plain text or HTML.voidUpdates the translator with the supported languages by means of requesting the information from the service.
Method Details
getReadyState
String getReadyState()Gets the ready state of this translator.- Returns:
- An error message describing the state (e.g. "Missing API key"), or null for OK.
getName
String getName()Returns the name of this translator.- Returns:
- A String with the name of the translator, e.g. "Google Translate" or "Azure Cognitive Services".
updateSupportedLanguages
void updateSupportedLanguages()Updates the translator with the supported languages by means of requesting the information from the service. If the request fails, it will be logged in the server.isLanguageHandled
Verifies if a Language Code is handled by this translator.- Parameters:
languageCode- The language code.- Returns:
- true if supported, false if not.
getLanguageCode
getLanguageDescription
canTranslate
translate
Translation translate(KString sourceText, String sourceLanguageCode, String targetLanguageCode) throws TranslationException, RequestException Translates a text in plain text or HTML.- Parameters:
sourceText- The source text to translate.sourceLanguageCode- The source language code, null for automatic detection.targetLanguageCode- The target language code.- Returns:
- The translation.
- Throws:
RequestException- If the translation web service failed.TranslationException- An exception for translation failure.
deconfigure
void deconfigure()Deconfigures the translator to "lose" the API key(s).