Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add override for Translator.translateText to get rid of null parsing for sourceLang to auto-detect #49

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions deepl-java/src/main/java/com/deepl/api/Translator.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ public static boolean isFreeAccountAuthKey(String authKey) {
return authKey != null && authKey.endsWith(":fx");
}

/**
* Functions the same as {@link Translator#translateText(String, String, String,
* TextTranslationOptions)} but sourceLang is auto-detected.
*/
public TextResult translateText(
String text,
String targetLang,
@Nullable TextTranslationOptions options)
throws InterruptedException, DeepLException {
ArrayList<String> texts = new ArrayList<>();
texts.add(text);
return translateText(texts, null, targetLang, options).get(0);
}

/**
* Translate specified text from source language into target language.
*
Expand Down Expand Up @@ -155,6 +169,20 @@ public TextResult translateText(String text, @Nullable Language sourceLang, Lang
text, (sourceLang != null) ? sourceLang.getCode() : null, targetLang.getCode(), null);
}

/**
* Functions the same as {@link Translator#translateText(String, String, String,
* TextTranslationOptions)} but accepts {@link Language} objects for target language and sourceLang is auto-detected.
*
* @see Translator#translateText(String, String, String, TextTranslationOptions)
*/
public TextResult translateText(
String text,
Language targetLang,
@Nullable TextTranslationOptions options)
throws DeepLException, InterruptedException {
return translateText(text, null, targetLang.getCode(), options);
}

/**
* Functions the same as {@link Translator#translateText(String, String, String,
* TextTranslationOptions)} but accepts {@link Language} objects for source and target languages.
Expand Down
Loading