public class CachedTranslator extends Object implements Translator
Constructor and Description |
---|
CachedTranslator(Translator translator)
Create a new CachedTranslator.
|
Modifier and Type | Method and Description |
---|---|
boolean |
contains(String text,
String targetLanguage)
Check whether this CachedTranslator's cache contains a translation of the text to the target language,
attempting to auto-detect the source language.
|
boolean |
contains(String text,
String sourceLanguage,
String targetLanguage)
Check whether this CachedTranslator's cache contains a translation of the text from the
source language to the target language.
|
int |
getNumTranslationPairs()
Get the number of different source/target translation pairs this CachedTranslator
currently has in its cache.
|
int |
getNumTranslationsFor(String sourceLanguage,
String targetLanguage)
Get the number of different translations from the source language to the target language
this CachedTranslator has in its cache.
|
boolean |
isAvailable() |
String |
translate(String text,
String targetLanguage)
Translate text to the given language.
|
String |
translate(String text,
String sourceLanguage,
String targetLanguage)
Translate text between given languages.
|
public CachedTranslator(Translator translator)
translator
- The translator that should be used for the underlying translation service. The properties
for that service must be set properly!public String translate(String text, String sourceLanguage, String targetLanguage) throws Exception
Translator
translate
in interface Translator
text
- The text to translate.sourceLanguage
- The input text language (for example, "en").targetLanguage
- The desired language to translate to (for example, "fr").Exception
- When there is an error with the API call.public String translate(String text, String targetLanguage) throws Exception
Translator
translate
in interface Translator
text
- The text to translate.targetLanguage
- The desired language to translate to (for example, "hi").Exception
- When there is an error with the API call.public boolean isAvailable()
isAvailable
in interface Translator
public int getNumTranslationPairs()
public int getNumTranslationsFor(String sourceLanguage, String targetLanguage)
sourceLanguage
- The source language of translation.targetLanguage
- The target language of translation.public boolean contains(String text, String sourceLanguage, String targetLanguage)
text
- What string to check for.sourceLanguage
- The source language of translation.targetLanguage
- The target language of translation.public boolean contains(String text, String targetLanguage)
text
- What string to check for.targetLanguage
- The target language of translation.Copyright © 2007-2014 The Apache Software Foundation. All Rights Reserved.