Skip to content

The DeepL Translator is an API written in Java that translates via the DeepL website sentences. Without API key.

License

Notifications You must be signed in to change notification settings

Linus789/DeepLTranslator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DeepLTranslator

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.

Prerequisites

  • ChromeDriver installed and located in PATH

Install

Maven

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>

Gradle

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'
}

Examples

Using a configuration

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);

Synchronous translating

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();
}

Asynchronous translating

deepLTranslator.translateAsync("Detected cow running backwards.", SourceLanguage.ENGLISH, TargetLanguage.GERMAN)
        .whenComplete((res, ex) -> {
            if (ex != null) {
                ex.printStackTrace();
            } else {
                System.out.println(res);
            }
        });

Await termination

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();
}

Shutdown

Stops all running threads

DeepLTranslator.shutdown();

Example

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details

About

The DeepL Translator is an API written in Java that translates via the DeepL website sentences. Without API key.

Topics

Resources

License

Stars

Watchers

Forks

Languages