Interface ITranslationEngine

All Known Implementing Classes:
EditorTranslationEngine, TestEngine, TranslationEngine

public interface ITranslationEngine
The translation engine interface.
Author:
Christopher Mindus
  • Field Details

    • REQTYPE_POST

      static final int REQTYPE_POST
      Type of request: normal POST.
      See Also:
    • REQTYPE_POST_OVERRIDES_GET

      static final int REQTYPE_POST_OVERRIDES_GET
      Type of request: POST with "X-HTTP-Method-Override" to GET.
      See Also:
  • Method Details

    • getTranslator

      ITranslator getTranslator(String sourceLanguageCode, String targetLanguageCode)
      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

      boolean isLanguageHandled(String languageCode)
      Verifies if a Language Code is handled by this translator.
      Parameters:
      languageCode - The language code.
      Returns:
      true if supported, false if not.
    • canTranslate

      boolean canTranslate(String sourceLanguageCode, String targetLanguageCode)
      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

      Proxy getProxy(URL url)
      Gets a proxy to use for an URL.
      Parameters:
      url - The URL.
      Returns:
      The Proxy to use.
    • configureProxy

      void configureProxy(HttpURLConnection urlConnection)
      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,String> headers, int type, int sizeLimit) throws IOException, JSONException
      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, JSONException
      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.
    • requestString

      String requestString(String httpRequest, Map<String,String> params, Map<String,String> headers, int type, int sizeLimit) throws IOException
      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 IOException
      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.
    • postRequestJSON

      String postRequestJSON(String httpRequest, Map<String,String> headers, String data) throws IOException
      Requests 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.