Class MicrosoftTranslator
java.lang.Object
org.apache.tika.language.translate.impl.MicrosoftTranslator
- All Implemented Interfaces:
Translator
Wrapper class to access the Windows translation service. This class uses the com.memetix.mst
package as a wrapper for the API calls.
- Since:
- Tika 1.6
-
Field Summary
-
Constructor Summary
ConstructorDescriptionCreate a new MicrosoftTranslator with the client keys specified in resources/org/apache/tika/language/translate/translator.microsoft.properties. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Check whether this instance has a working property file and its keys are not the defaults.void
Sets the client Id for the translator API.void
Sets the client secret for the translator API.Use the Microsoft service to translate the given text to the given target language.Use the Microsoft service to translate the given text from the given source language to the given target.
-
Field Details
-
PROPERTIES_FILE
- See Also:
-
ID_PROPERTY
- See Also:
-
SECRET_PROPERTY
- See Also:
-
DEFAULT_ID
- See Also:
-
DEFAULT_SECRET
- See Also:
-
-
Constructor Details
-
MicrosoftTranslator
public MicrosoftTranslator()Create a new MicrosoftTranslator with the client keys specified in resources/org/apache/tika/language/translate/translator.microsoft.properties. Silently becomes unavailable when client keys are unavailable. translator.microsoft.client-id and translator.client-secret must be set in translator.microsoft.properties for translation to work.- Since:
- Tika 1.6
-
-
Method Details
-
translate
public String translate(String text, String sourceLanguage, String targetLanguage) throws TikaException, IOException Use the Microsoft service to translate the given text from the given source language to the given target. You must set the client keys in translator.microsoft.properties.- 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 translated text. If translation is unavailable, returns the unchanged text.
- Throws:
Exception
TikaException
- When there is an error translating.IOException
- Since:
- Tika 1.6
- See Also:
-
translate
Use the Microsoft service to translate the given text to the given target language. The source language is automatically detected by Microsoft. You must set the client keys in translator.microsoft.properties.- Specified by:
translate
in interfaceTranslator
- Parameters:
text
- The text to translate.targetLanguage
- The desired language to translate to (for example, "hi").- Returns:
- The translated text. If translation is unavailable, returns the unchanged text.
- Throws:
Exception
TikaException
- When there is an error translating.IOException
- Since:
- Tika 1.6
- See Also:
-
isAvailable
public boolean isAvailable()Check whether this instance has a working property file and its keys are not the defaults. This is not guaranteed to work, since keys may be incorrect or the webservice may be down.- Specified by:
isAvailable
in interfaceTranslator
- Returns:
- whether translation will probably work.
-
setId
Sets the client Id for the translator API.- Parameters:
id
- The ID to set.
-
setSecret
Sets the client secret for the translator API.- Parameters:
secret
- The secret to set.
-