Class DefaultTranslator
- java.lang.Object
-
- org.apache.tika.language.translate.DefaultTranslator
-
- All Implemented Interfaces:
Translator
public class DefaultTranslator extends Object implements Translator
A translator which picks the first availableTranslator
implementations available through theservice provider mechanism
.- Since:
- Apache Tika 1.6
-
-
Constructor Summary
Constructors Constructor Description DefaultTranslator()
DefaultTranslator(ServiceLoader loader)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Translator
getTranslator()
Returns the current translatorList<Translator>
getTranslators()
Returns all available translatorsboolean
isAvailable()
String
translate(String text, String targetLanguage)
Translate, using the first available service-loaded translatorString
translate(String text, String sourceLanguage, String targetLanguage)
Translate, using the first available service-loaded translator
-
-
-
Constructor Detail
-
DefaultTranslator
public DefaultTranslator(ServiceLoader loader)
-
DefaultTranslator
public DefaultTranslator()
-
-
Method Detail
-
translate
public String translate(String text, String sourceLanguage, String targetLanguage) throws TikaException, IOException
Translate, using the first available service-loaded translator- Specified by:
translate
in interfaceTranslator
- 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.IOException
-
translate
public String translate(String text, String targetLanguage) throws TikaException, IOException
Translate, using the first available service-loaded translator- Specified by:
translate
in interfaceTranslator
- 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.IOException
-
getTranslators
public List<Translator> getTranslators()
Returns all available translators
-
getTranslator
public Translator getTranslator()
Returns the current translator
-
isAvailable
public boolean isAvailable()
- Specified by:
isAvailable
in interfaceTranslator
- Returns:
- true if this Translator is probably able to translate right now.
-
-