Package com.iizix.translate
Interface ITranslationEngine
- All Known Implementing Classes:
EditorTranslationEngine,TestEngine,TranslationEngine
public interface ITranslationEngine
The translation engine interface.
- Author:
- Christopher Mindus
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intType of request: normal POST.static final intType of request: POST with "X-HTTP-Method-Override" to GET.Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Cancels pending or running translation job.booleancanTranslate(String sourceLanguageCode, String targetLanguageCode) Checks if a translation is handled between two language codes.voidconfigureProxy(HttpURLConnection urlConnection) Configures a Http(s)URLConnection for proxy information.Gets a proxy to use for an URL.Gets the translation queues.Gets the ready state of this translation engine.getTranslator(String sourceLanguageCode, String targetLanguageCode) Gets the translator to use for a particular language combination.booleanisLanguageHandled(String languageCode) Verifies if a Language Code is handled by this translator.Requests a function using HTTPS POST, configured for proxy as specified in Eclipse or the Server.Requests a function using HTTPS GET or POST with "X-HTTP-Method-Override: GET", configured for proxy as specified in Eclipse or the Server.requestJSON(String httpRequest, Map<String, String> params, Map<String, String> headers, int type, int sizeLimit) Requests a function using HTTPS GET or POST with "X-HTTP-Method-Override: GET", configured for proxy as specified in Eclipse or the Server.requestString(String httpRequest, String params, Map<String, String> headers, int type, int sizeLimit) Requests a function using HTTPS GET or POST with "X-HTTP-Method-Override: GET", configured for proxy as specified in Eclipse or the Server.requestString(String httpRequest, Map<String, String> params, Map<String, String> headers, int type, int sizeLimit) Requests a function using HTTPS GET or POST with "X-HTTP-Method-Override: GET", configured for proxy as specified in Eclipse or the Server.booleantranslate(KString sourceText, String sourceLanguageCode, String targetLanguageCode, ITranslationReply replyCallback) Translates a text in plain text or HTML.
Field Details
REQTYPE_POST
static final int REQTYPE_POSTType of request: normal POST.- See Also:
REQTYPE_POST_OVERRIDES_GET
static final int REQTYPE_POST_OVERRIDES_GETType of request: POST with "X-HTTP-Method-Override" to GET.- See Also:
Method Details
getTranslator
Gets the translator to use for a particular language combination.- Parameters:
sourceLanguageCode- The source language code, null for automatic detection.targetLanguageCode- The target language code.- Returns:
- The translator, null for not found or not configured.
getQueues
TranslationQueue[] getQueues()Gets the translation queues.- Returns:
- The array of translation queues.
getReadyState
String getReadyState()Gets the ready state of this translation engine.- Returns:
- An error message describing the state (e.g. "Not configured"), or null for OK.
isLanguageHandled
Verifies if a Language Code is handled by this translator.- Parameters:
languageCode- The language code.- Returns:
- true if supported, false if not.
canTranslate
Checks if a translation is handled between two language codes.- Parameters:
sourceLanguageCode- The source language code, null for automatic detection.targetLanguageCode- The target language code.- Returns:
- true if supported, false if not.
translate
boolean translate(KString sourceText, String sourceLanguageCode, String targetLanguageCode, ITranslationReply replyCallback) 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.replyCallback- Callback when translation completes.- Returns:
- true for success, false for failure (error is logged).
cancel
void cancel()Cancels pending or running translation job.getProxy
Gets a proxy to use for an URL.- Parameters:
url- The URL.- Returns:
- The Proxy to use.
configureProxy
Configures a Http(s)URLConnection for proxy information.- Parameters:
urlConnection- The HttpURLConnection or HttpsURLConnection.
requestJSON
JSONObject requestJSON(String httpRequest, Map<String, String> params, Map<String, throws IOException, JSONExceptionString> headers, int type, int sizeLimit) Requests a function using HTTPS GET or POST with "X-HTTP-Method-Override: GET", configured for proxy as specified in Eclipse or the Server.- Parameters:
httpRequest- The request string.params- The parameters, null for none.headers- The HTTP headers, null for none.type- Type of request: REQTYPE_* value.sizeLimit- The size limit imposed, 5120 for Google, 10K for Microsoft.- Returns:
- The parsed JSON object.
- Throws:
IOException- For I/O errors.JSONException- For JSON exceptions.
requestJSON
JSONObject requestJSON(String httpRequest, String params, Map<String, String> headers, int type, int sizeLimit) throws IOException, JSONExceptionRequests a function using HTTPS GET or POST with "X-HTTP-Method-Override: GET", configured for proxy as specified in Eclipse or the Server.- Parameters:
httpRequest- The request string.params- The parameters, null for none.headers- The HTTP headers, null for none.type- Type of request: REQTYPE_* value.sizeLimit- The size limit imposed, 5120 for Google, 10K for Microsoft.- Returns:
- The parsed JSON object.
- Throws:
IOException- For I/O errors.JSONException- For JSON exceptions.
requestString
String requestString(String httpRequest, Map<String, String> params, Map<String, throws IOExceptionString> headers, int type, int sizeLimit) Requests a function using HTTPS GET or POST with "X-HTTP-Method-Override: GET", configured for proxy as specified in Eclipse or the Server.- Parameters:
httpRequest- The request string.params- The parameters, null for none.headers- The HTTP headers, null for none.type- Type of request: REQTYPE_* value.sizeLimit- The size limit imposed, 5120 for Google, 10K for Microsoft.- Returns:
- The reply string.
- Throws:
IOException- For I/O errors.
requestString
String requestString(String httpRequest, String params, Map<String, String> headers, int type, int sizeLimit) throws IOExceptionRequests a function using HTTPS GET or POST with "X-HTTP-Method-Override: GET", configured for proxy as specified in Eclipse or the Server.- Parameters:
httpRequest- The request string.params- The parameters, null for none.headers- The HTTP headers, null for none.type- Type of request: REQTYPE_* value.sizeLimit- The size limit imposed, 5120 for Google, 10K for Microsoft.- Returns:
- The reply string.
- Throws:
IOException- For I/O errors.
postRequestJSON
String postRequestJSON(String httpRequest, Map<String, String> headers, String data) throws IOExceptionRequests a function using HTTPS POST, configured for proxy as specified in Eclipse or the Server.- Parameters:
httpRequest- The request string.headers- The HTTP headers, never null.data- The data string.- Returns:
- The reply string.
- Throws:
IOException- For I/O errors.