Package com.iizix.translate
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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
canTranslate(java.lang.String sourceLanguageCode, java.lang.String targetLanguageCode)
Checks if a translation is handled between two language codes.void
deconfigure()
Deconfigures the translator to "lose" the API key(s).java.lang.String
getLanguageCode(java.lang.String languageCode)
Gets the "real" language code, no matter the input case.java.lang.String
getLanguageDescription(java.lang.String languageCode)
Gets the language description for a language code, e.g.java.lang.String
getName()
Returns the name of this translator.java.lang.String
getReadyState()
Gets the ready state of this translator.boolean
isLanguageHandled(java.lang.String languageCode)
Verifies if a Language Code is handled by this translator.Translation
translate(KString sourceText, java.lang.String sourceLanguageCode, java.lang.String targetLanguageCode)
Translates a text in plain text or HTML.void
updateSupportedLanguages()
Updates the translator with the supported languages by means of requesting the information from the service.
Method Detail
getReadyState
java.lang.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
java.lang.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
boolean isLanguageHandled(java.lang.String languageCode)
Verifies if a Language Code is handled by this translator.- Parameters:
languageCode
- The language code.- Returns:
- true if supported, false if not.
getLanguageCode
java.lang.String getLanguageCode(java.lang.String languageCode)
Gets the "real" language code, no matter the input case.- Parameters:
languageCode
- The language code.- Returns:
- The potentially changed language code if the case was wrong, or null if language is not supported.
getLanguageDescription
java.lang.String getLanguageDescription(java.lang.String languageCode)
Gets the language description for a language code, e.g. "sv" would be "Swedish".- Parameters:
languageCode
- The language code.- Returns:
- The language description the current Eclipse + IIZI language (English only for now).
canTranslate
boolean canTranslate(java.lang.String sourceLanguageCode, java.lang.String targetLanguageCode)
Checks if a translation is handled between two language codes.- Parameters:
sourceLanguageCode
- The source language code.targetLanguageCode
- The target language code.- Returns:
- true if supported, false if not.
translate
Translation translate(KString sourceText, java.lang.String sourceLanguageCode, java.lang.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).