Class DefaultTranslator

  • All Implemented Interfaces:
    Translator

    public class DefaultTranslator
    extends java.lang.Object
    implements Translator
    A translator which picks the first available Translator implementations available through the service provider mechanism.
    Since:
    Apache Tika 1.6
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Translator getTranslator()
      Returns the current translator
      java.util.List<Translator> getTranslators()
      Returns all available translators
      boolean isAvailable()  
      java.lang.String translate​(java.lang.String text, java.lang.String targetLanguage)
      Translate, using the first available service-loaded translator
      java.lang.String translate​(java.lang.String text, java.lang.String sourceLanguage, java.lang.String targetLanguage)
      Translate, using the first available service-loaded translator
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DefaultTranslator

        public DefaultTranslator​(ServiceLoader loader)
      • DefaultTranslator

        public DefaultTranslator()
    • Method Detail

      • translate

        public java.lang.String translate​(java.lang.String text,
                                          java.lang.String sourceLanguage,
                                          java.lang.String targetLanguage)
                                   throws TikaException,
                                          java.io.IOException
        Translate, using the first available service-loaded translator
        Specified by:
        translate in interface Translator
        Parameters:
        text - The text to translate.
        sourceLanguage - The input text language (for example, "en").
        targetLanguage - The desired language to translate to (for example, "fr").
        Returns:
        The translation result. If translation is unavailable, returns the same text back.
        Throws:
        TikaException - When there is an error translating.
        java.io.IOException
      • translate

        public java.lang.String translate​(java.lang.String text,
                                          java.lang.String targetLanguage)
                                   throws TikaException,
                                          java.io.IOException
        Translate, using the first available service-loaded translator
        Specified by:
        translate in interface Translator
        Parameters:
        text - The text to translate.
        targetLanguage - The desired language to translate to (for example, "hi").
        Returns:
        The translation result. If translation is unavailable, returns the same text back.
        Throws:
        TikaException - When there is an error translating.
        java.io.IOException
      • getTranslators

        public java.util.List<Translator> getTranslators()
        Returns all available translators
      • getTranslator

        public Translator getTranslator()
        Returns the current translator
      • isAvailable

        public boolean isAvailable()
        Specified by:
        isAvailable in interface Translator
        Returns:
        true if this Translator is probably able to translate right now.