This project is a simple DeepL Translator API written in Java. It translates via the DeepL website sentences. This works without having a premium access and can be used free of charge.
- ChromeDriver installed and located in PATH
Add the JitPack repository in your pom.xml
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
Add the dependency
<dependency>
<groupId>com.github.Linus789</groupId>
<artifactId>DeepLTranslator</artifactId>
<version>2.1.0</version>
</dependency>
Add the JitPack repository in your root build.gradle at the end of repositories
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add the dependency
dependencies {
implementation 'com.github.Linus789:DeepLTranslator:2.1.0'
}
DeepLConfiguration deepLConfiguration = new DeepLConfiguration.Builder()
.setTimeout(Duration.ofSeconds(10))
.setRepetitions(3)
.setRepetitionsDelay(retryNumber -> Duration.ofMillis(3000 + 5000 * retryNumber))
.setPostProcessing(false)
.build();
DeepLTranslator deepLTranslator = new DeepLTranslator(deepLConfiguration);
try {
String translation = deepLTranslator.translate("I ran into a similar problem yesterday.", SourceLanguage.ENGLISH, TargetLanguage.GERMAN);
System.out.println(translation);
} catch (Exception e) {
e.printStackTrace();
}
deepLTranslator.translateAsync("Detected cow running backwards.", SourceLanguage.ENGLISH, TargetLanguage.GERMAN)
.whenComplete((res, ex) -> {
if (ex != null) {
ex.printStackTrace();
} else {
System.out.println(res);
}
});
Blocks until all async translations from one DeepLTranslator
instance have completed execution, or the timeout occurs,
or the current thread is interrupted, whichever happens first.
try {
deepLTranslator.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
Stops all running threads
DeepLTranslator.shutdown();
This project is licensed under the Apache License 2.0 - see the LICENSE file for details