Class GoogleTranslator
java.lang.Object
org.apache.tika.language.translate.impl.AbstractTranslator
org.apache.tika.language.translate.impl.GoogleTranslator
- All Implemented Interfaces:
Translator
An implementation of a REST client to the Google Translate v2
API. Based on the great tutorial
from hayageek.com. Set your API key in
translator.google.properties.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Translate text to the given language This method attempts to auto-detect the source language of the text.Translate text between given languages.Methods inherited from class org.apache.tika.language.translate.impl.AbstractTranslator
detectLanguage
-
Constructor Details
-
GoogleTranslator
public GoogleTranslator()
-
-
Method Details
-
translate
public String translate(String text, String sourceLanguage, String targetLanguage) throws TikaException, IOException Description copied from interface:Translator
Translate text between given languages.- 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
Description copied from interface:Translator
Translate text to the given language This method attempts to auto-detect the source language of the text.- 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
-
isAvailable
public boolean isAvailable()- Returns:
- true if this Translator is probably able to translate right now.
-