25 lines
1.1 KiB
Markdown
25 lines
1.1 KiB
Markdown
# libjf-translate-v0
|
|
libjf-translate-v0 provides a utility class for translating strings through Google Translate.
|
|
|
|
To use this, first obtain a TranslateService instance. You can use `TranslateService.getConfigured()` to do so.
|
|
Please be aware that due to the nature of java generics, a workaround as seen in the example may be needed for successful compilation.
|
|
You can also directly access implementations, however, this is not recommended.
|
|
The TranslateService interface exposes all relevant functionality.
|
|
|
|
Example:
|
|
```java
|
|
public void onInitialize() {
|
|
try {
|
|
runTest(TranslateService.getConfigured());
|
|
} catch (Throwable e) {
|
|
LibJf.LOGGER.error("Could not verify translation validity", e);
|
|
}
|
|
}
|
|
|
|
private <T> void runTest(TranslateService<T> ts) throws TranslateException {
|
|
final String source = "Cogito, ergo sum";
|
|
final String expected = "I think, therefore I am";
|
|
assert expected.equals(ts.translate(source, ts.detect(source), ts.parseLang("en")));
|
|
assert expected.equals(ts.translate(source, ts.parseLang("la"), ts.parseLang("en")));
|
|
}
|
|
``` |