Allows setting max lines and max line length, enables DeepL, adds user setup bridge
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
package com.github.gtache.autosubtitle;
|
||||
|
||||
import com.github.gtache.autosubtitle.subtitle.Subtitle;
|
||||
import com.github.gtache.autosubtitle.subtitle.SubtitleCollection;
|
||||
|
||||
/**
|
||||
* Translates texts and subtitles
|
||||
*/
|
||||
public interface Translator<T extends Subtitle> {
|
||||
|
||||
/**
|
||||
* Guesses the language of the given text
|
||||
*
|
||||
* @param text The text
|
||||
* @return The guessed language
|
||||
*/
|
||||
Language getLanguage(final String text);
|
||||
|
||||
/**
|
||||
* Guesses the language of the given subtitle
|
||||
*
|
||||
* @param subtitle The subtitle
|
||||
* @return The guessed language
|
||||
*/
|
||||
default Language getLanguage(final Subtitle subtitle) {
|
||||
return getLanguage(subtitle.content());
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the given text to the given language
|
||||
*
|
||||
* @param text The text to translate
|
||||
* @param to The target language
|
||||
* @return The translated text
|
||||
*/
|
||||
String translate(String text, Language to);
|
||||
|
||||
/**
|
||||
* Translates the given subtitle to the given language
|
||||
*
|
||||
* @param subtitle The subtitle to translate
|
||||
* @param to The target language
|
||||
* @return The translated subtitle
|
||||
*/
|
||||
T translate(Subtitle subtitle, Language to);
|
||||
|
||||
/**
|
||||
* Translates the given subtitles collection to the given language
|
||||
*
|
||||
* @param collection The subtitles collection to translate
|
||||
* @param to The target language
|
||||
* @return The translated subtitles collection
|
||||
*/
|
||||
SubtitleCollection<T> translate(SubtitleCollection<?> collection, Language to);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.github.gtache.autosubtitle.setup;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Bridge between setup manager and the user
|
||||
*/
|
||||
public interface SetupUserBridge {
|
||||
|
||||
/**
|
||||
* Asks for user input
|
||||
*
|
||||
* @param question the question to display to the user
|
||||
* @return the user input
|
||||
*/
|
||||
String askForUserInput(String question);
|
||||
|
||||
/**
|
||||
* Asks for user choice
|
||||
*
|
||||
* @param question the question to display to the user
|
||||
* @param choices the possible choices
|
||||
* @param <T> the type of the choices
|
||||
* @return the user choice
|
||||
*/
|
||||
<T> T askForUserChoice(String question, List<T> choices);
|
||||
|
||||
/**
|
||||
* Asks for user confirmation
|
||||
*
|
||||
* @param question the question to display to the user
|
||||
* @return whether the user confirmed
|
||||
*/
|
||||
boolean askForUserConfirmation(String question);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.github.gtache.autosubtitle.translation;
|
||||
|
||||
/**
|
||||
* Exception thrown when an error occurs during translation
|
||||
*/
|
||||
public class TranslationException extends Exception {
|
||||
|
||||
public TranslationException(final String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public TranslationException(final String message, final Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public TranslationException(final Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.github.gtache.autosubtitle.translation;
|
||||
|
||||
import com.github.gtache.autosubtitle.Language;
|
||||
import com.github.gtache.autosubtitle.subtitle.Subtitle;
|
||||
import com.github.gtache.autosubtitle.subtitle.SubtitleCollection;
|
||||
|
||||
/**
|
||||
* Translates texts and subtitles
|
||||
*/
|
||||
public interface Translator<T extends Subtitle> {
|
||||
|
||||
/**
|
||||
* Guesses the language of the given text
|
||||
*
|
||||
* @param text The text
|
||||
* @return The guessed language
|
||||
*/
|
||||
Language getLanguage(final String text);
|
||||
|
||||
/**
|
||||
* Guesses the language of the given subtitle
|
||||
*
|
||||
* @param subtitle The subtitle
|
||||
* @return The guessed language
|
||||
*/
|
||||
default Language getLanguage(final Subtitle subtitle) {
|
||||
return getLanguage(subtitle.content());
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the given text to the given language
|
||||
*
|
||||
* @param text The text to translate
|
||||
* @param to The target language
|
||||
* @return The translated text
|
||||
* @throws TranslationException if an error occurred during the translation
|
||||
*/
|
||||
default String translate(final String text, final Language to) throws TranslationException {
|
||||
return translate(text, getLanguage(text), to);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the given text to the given language
|
||||
*
|
||||
* @param text The text to translate
|
||||
* @param from The source language
|
||||
* @param to The target language
|
||||
* @return The translated text
|
||||
* @throws TranslationException if an error occurred during the translation
|
||||
*/
|
||||
String translate(String text, Language from, Language to) throws TranslationException;
|
||||
|
||||
/**
|
||||
* Translates the given subtitle to the given language
|
||||
*
|
||||
* @param subtitle The subtitle to translate
|
||||
* @param to The target language
|
||||
* @return The translated subtitle
|
||||
* @throws TranslationException if an error occurred during the translation
|
||||
*/
|
||||
default T translate(final Subtitle subtitle, final Language to) throws TranslationException {
|
||||
return translate(subtitle, getLanguage(subtitle), to);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the given subtitle to the given language
|
||||
*
|
||||
* @param subtitle The subtitle to translate
|
||||
* @param from The source language
|
||||
* @param to The target language
|
||||
* @return The translated subtitle
|
||||
* @throws TranslationException if an error occurred during the translation
|
||||
*/
|
||||
T translate(Subtitle subtitle, Language from, Language to) throws TranslationException;
|
||||
|
||||
/**
|
||||
* Translates the given subtitles collection to the given language
|
||||
*
|
||||
* @param collection The subtitles collection to translate
|
||||
* @param to The target language
|
||||
* @return The translated subtitles collection
|
||||
* @throws TranslationException if an error occurred during the translation
|
||||
*/
|
||||
default SubtitleCollection<T> translate(final SubtitleCollection<?> collection, final Language to) throws TranslationException {
|
||||
return translate(collection, getLanguage(collection.text()), to);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the given subtitles collection to the given language
|
||||
*
|
||||
* @param collection The subtitles collection to translate
|
||||
* @param from The source language
|
||||
* @param to The target language
|
||||
* @return The translated subtitles collection
|
||||
* @throws TranslationException if an error occurred during the translation
|
||||
*/
|
||||
SubtitleCollection<T> translate(SubtitleCollection<?> collection, Language from, Language to) throws TranslationException;
|
||||
}
|
||||
@@ -9,4 +9,5 @@ module com.github.gtache.autosubtitle.api {
|
||||
exports com.github.gtache.autosubtitle.subtitle;
|
||||
exports com.github.gtache.autosubtitle.subtitle.extractor;
|
||||
exports com.github.gtache.autosubtitle.subtitle.converter;
|
||||
exports com.github.gtache.autosubtitle.translation;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.github.gtache.autosubtitle;
|
||||
|
||||
import com.github.gtache.autosubtitle.subtitle.Subtitle;
|
||||
import com.github.gtache.autosubtitle.translation.Translator;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
|
||||
Reference in New Issue
Block a user