All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.elypia.elypiai.google.translate.GoogleTranslate Maven / Gradle / Ivy

The newest version!
package com.elypia.elypiai.google.translate;

import com.elypia.elypiai.utils.Language;

import java.io.IOException;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;

public class GoogleTranslate {

    private String apiKey;
    private TranslationRequester requester;
    private List supportedLanguages;

    public GoogleTranslate(String apiKey) {
        this.apiKey = Objects.requireNonNull(apiKey);
        requester = new TranslationRequester(this, apiKey);

        requester.getSupportedLanguages(o -> {
            supportedLanguages = o;
        }, IOException::printStackTrace);
    }

    public void getSupportedLanguages(Consumer> success, Consumer failure) {
        requester.getSupportedLanguages(success, failure);
    }

    public void translate(String body, Language target, Consumer success, Consumer failure) {
        translate(body, null, target, success, failure);
    }

    public void translate(String body, Language source, Language target, Consumer success, Consumer failure) {
        requester.translate(body, source, target, success, failure);
    }

    public boolean isSupportedLanguage(Language language) {
        return supportedLanguages.contains(language);
    }

    public List getSupportedLanguages() {
        return supportedLanguages;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy