Adds WhisperX, reworks UI (still needs some work), theoretically usable
This commit is contained in:
@@ -1,35 +1,52 @@
|
||||
package com.github.gtache.autosubtitle.gui.impl;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Combines multiple resource bundles
|
||||
*/
|
||||
public class CombinedResourceBundle extends ResourceBundle {
|
||||
private static final Logger logger = LogManager.getLogger(CombinedResourceBundle.class);
|
||||
|
||||
private final Map<String, String> resources;
|
||||
private final Locale locale;
|
||||
|
||||
public CombinedResourceBundle(final ResourceBundle... bundles) {
|
||||
this(Arrays.asList(bundles));
|
||||
public CombinedResourceBundle(final ResourceBundle... resourceBundles) {
|
||||
this(Arrays.asList(resourceBundles));
|
||||
}
|
||||
|
||||
public CombinedResourceBundle(final Iterable<ResourceBundle> bundles) {
|
||||
public CombinedResourceBundle(final List<ResourceBundle> resourceBundles) {
|
||||
final var filteredBundles = resourceBundles.stream().filter(Objects::nonNull).toList();
|
||||
if (filteredBundles.size() != resourceBundles.size()) {
|
||||
logger.warn("There was one or more null bundles in the inner bundles");
|
||||
}
|
||||
if (filteredBundles.isEmpty()) {
|
||||
throw new IllegalArgumentException("The bundle should contain at least one bundle");
|
||||
}
|
||||
this.resources = new HashMap<>();
|
||||
bundles.forEach(rb -> rb.getKeys().asIterator().forEachRemaining(key -> resources.put(key, rb.getString(key))));
|
||||
filteredBundles.forEach(r -> r.keySet().forEach(s -> resources.put(s, r.getString(s))));
|
||||
this.locale = filteredBundles.getFirst().getLocale();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object handleGetObject(final String key) {
|
||||
return resources.get(key);
|
||||
public Object handleGetObject(final String key) {
|
||||
if (resources.containsKey(key)) {
|
||||
return resources.get(key);
|
||||
} else {
|
||||
throw new MissingResourceException(key + " not found", "CombinedResourceBundle", key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getKeys() {
|
||||
return Collections.enumeration(resources.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.github.gtache.autosubtitle.gui.impl.spi;
|
||||
|
||||
import java.util.spi.ResourceBundleProvider;
|
||||
|
||||
/**
|
||||
* Provider for SubtitlesBundle
|
||||
*/
|
||||
public interface SubtitlesBundleProvider extends ResourceBundleProvider {
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.github.gtache.autosubtitle.gui.impl.spi;
|
||||
|
||||
import java.util.spi.AbstractResourceBundleProvider;
|
||||
|
||||
/**
|
||||
* Implementation of {@link SubtitlesBundleProvider}
|
||||
*/
|
||||
public class SubtitlesBundleProviderImpl extends AbstractResourceBundleProvider implements SubtitlesBundleProvider {
|
||||
}
|
||||
@@ -23,6 +23,7 @@ public final class GuiCoreModule {
|
||||
ResourceBundle.getBundle("com.github.gtache.autosubtitle.gui.impl.SetupBundle"),
|
||||
ResourceBundle.getBundle("com.github.gtache.autosubtitle.gui.impl.WorkBundle"),
|
||||
ResourceBundle.getBundle("com.github.gtache.autosubtitle.gui.impl.ParametersBundle"),
|
||||
ResourceBundle.getBundle("com.github.gtache.autosubtitle.gui.impl.SubtitlesBundle"),
|
||||
ResourceBundle.getBundle("com.github.gtache.autosubtitle.gui.impl.MediaBundle"));
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.github.gtache.autosubtitle.gui.impl.spi.WorkBundleProviderImpl;
|
||||
module com.github.gtache.autosubtitle.gui.core {
|
||||
requires transitive com.github.gtache.autosubtitle.gui.api;
|
||||
requires transitive com.github.gtache.autosubtitle.core;
|
||||
requires org.apache.logging.log4j;
|
||||
exports com.github.gtache.autosubtitle.gui.impl;
|
||||
exports com.github.gtache.autosubtitle.gui.impl.spi;
|
||||
exports com.github.gtache.autosubtitle.modules.gui.impl;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
subtitles.button.load.label=Load subtitles...
|
||||
subtitles.button.reset.label=Reset subtitles
|
||||
subtitles.button.subtitles.save.label=Save subtitles...
|
||||
subtitles.export.error.label=Error during the export : {0}
|
||||
subtitles.export.error.title=Error exporting
|
||||
subtitles.language.label=Video language
|
||||
subtitles.load.error.label=Error loading subtitles : {0}
|
||||
subtitles.load.error.title=Error loading
|
||||
subtitles.save.error.label=Error saving subtitles : {0}
|
||||
subtitles.save.error.title=Error saving
|
||||
subtitles.table.column.from.label=From
|
||||
subtitles.table.column.text.label=Text
|
||||
subtitles.table.column.to.label=To
|
||||
subtitles.translate.label=Automatic translations
|
||||
@@ -0,0 +1,14 @@
|
||||
subtitles.button.load.label=Charger des sous-titres...
|
||||
subtitles.button.reset.label=R\u00E9initialiser les sous-titres
|
||||
subtitles.button.subtitles.save.label=Sauvegarder les sous-titres...
|
||||
subtitles.export.error.label=Erreur durant l''export : {0}
|
||||
subtitles.export.error.title=Erreur d'export
|
||||
subtitles.language.label=Langage de la vid\u00E9o
|
||||
subtitles.load.error.label=Erreur de chargement des sous-titres : {0}
|
||||
subtitles.load.error.title=Erreur de chargement
|
||||
subtitles.save.error.label=Erreur de sauvegarde des sous-titres : {0}
|
||||
subtitles.save.error.title=Erreur lors de la sauvegarde
|
||||
subtitles.table.column.from.label=De
|
||||
subtitles.table.column.text.label=Texte
|
||||
subtitles.table.column.to.label=\u00C0
|
||||
subtitles.translate.label=Traductions
|
||||
@@ -4,27 +4,13 @@ work.button.export.soft.label=Export video...
|
||||
work.button.export.soft.tooltip=Adds the subtitles to the video. This allows a video to have multiple subtitles and to enable them at will.
|
||||
work.button.extract.label=Extract subtitles
|
||||
work.button.file.label=Open video...
|
||||
work.button.load.label=Load subtitles...
|
||||
work.button.reset.label=Reset subtitles
|
||||
work.button.subtitles.save.label=Save subtitles...
|
||||
work.export.error.label=Error during the export : {0}
|
||||
work.export.error.title=Error exporting
|
||||
work.extract.error.label=Error extracting subtitles : {0}
|
||||
work.extract.error.title=Error extracting
|
||||
work.language.label=Video language
|
||||
work.load.subtitles.error.label=Error loading subtitles : {0}
|
||||
work.load.subtitles.error.title=Error loading
|
||||
work.load.video.error.label=Error loading video : {0}
|
||||
work.load.video.error.title=Error loading
|
||||
work.save.subtitles.error.label=Error saving subtitles : {0}
|
||||
work.save.subtitles.error.title=Error saving
|
||||
work.save.subtitles.missing.converter.label=No converter found for {0}
|
||||
work.save.subtitles.missing.converter.title=No converter found
|
||||
work.status.exporting.label=Exporting...
|
||||
work.status.extracting.label=Extracting...
|
||||
work.status.idle.label=Idle
|
||||
work.status.translating.label=Translating...
|
||||
work.table.column.from.label=From
|
||||
work.table.column.text.label=Text
|
||||
work.table.column.to.label=To
|
||||
work.translate.label=Automatic translations
|
||||
work.status.translating.label=Translating...
|
||||
@@ -4,25 +4,13 @@ work.button.export.soft.label=Exporter la vid\u00E9o...
|
||||
work.button.export.soft.tooltip=Ajoute les sous-titres \u00E0 la vid\u00E9o. Cela permet d'avoir plusieurs pistes de sous-titres dans une m\u00EAme vid\u00E9o et de les activer comme d\u00E9sir\u00E9.
|
||||
work.button.extract.label=Extraire les sous-titres
|
||||
work.button.file.label=Ouvrir une vid\u00E9o...
|
||||
work.button.load.label=Charger des sous-titres...
|
||||
work.button.reset.label=R\u00E9initialiser les sous-titres
|
||||
work.button.subtitles.save.label=Sauvegarder les sous-titres...
|
||||
work.export.error.label=Erreur durant l''export : {0}
|
||||
work.export.error.title=Erreur d'export
|
||||
work.extract.error.label=Erreur durant l''extraction des sous-titres : {0}
|
||||
work.extract.error.title=Erreur d'extraction
|
||||
work.language.label=Language de la vid\u00E9o
|
||||
work.load.subtitles.error.label=Erreur de chargement des sous-titres : {0}
|
||||
work.load.subtitles.error.title=Erreur de chargement
|
||||
work.load.video.error.label=Erreur lors du chargement de la vid\u00E9o : {0}
|
||||
work.load.video.error.title=Erreur de chargement
|
||||
work.save.subtitles.missing.converter.label=Aucun convertisseur trouv\u00E9 pour {0}
|
||||
work.save.subtitles.missing.converter.title=Aucun convertisseur trouv\u00E9
|
||||
work.status.exporting.label=Exportation en cours...
|
||||
work.status.extracting.label=Extraction en cours...
|
||||
work.status.idle.label=Idle
|
||||
work.status.translating.label=Traduction en cours...
|
||||
work.table.column.from.label=De
|
||||
work.table.column.text.label=Texte
|
||||
work.table.column.to.label=\u00C0
|
||||
work.translate.label=Traductions automatiques
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.github.gtache.autosubtitle.gui.impl;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class TestCombinedResourceBundle {
|
||||
|
||||
private static final ResourceBundle BUNDLE = new CombinedResourceBundle(
|
||||
ResourceBundle.getBundle("com.github.gtache.autosubtitle.gui.impl.MultiBundle", Locale.FRENCH),
|
||||
ResourceBundle.getBundle("com.github.gtache.autosubtitle.gui.impl.MultiBundleTwo", Locale.FRENCH));
|
||||
|
||||
@Test
|
||||
void testIllegal() {
|
||||
assertThrows(IllegalArgumentException.class, CombinedResourceBundle::new);
|
||||
assertThrows(IllegalArgumentException.class, () -> new CombinedResourceBundle(null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWorks() {
|
||||
assertEquals("deux", BUNDLE.getString("a"));
|
||||
assertEquals("deux", BUNDLE.getString("b"));
|
||||
assertEquals("trois", BUNDLE.getString("c"));
|
||||
assertEquals("un", BUNDLE.getString("d"));
|
||||
assertEquals(Arrays.asList("a", "b", "c", "d"), Collections.list(BUNDLE.getKeys()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNotFound() {
|
||||
assertThrows(MissingResourceException.class, () -> BUNDLE.getString("e"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLocale() {
|
||||
final var bundle = mock(ResourceBundle.class);
|
||||
when(bundle.keySet()).thenReturn(Set.of());
|
||||
when(bundle.getString(anyString())).thenReturn("");
|
||||
final var locale = mock(Locale.class);
|
||||
when(bundle.getLocale()).thenReturn(locale);
|
||||
final var combined = new CombinedResourceBundle(bundle);
|
||||
assertEquals(locale, combined.getLocale());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.github.gtache.autosubtitle.modules.gui.impl;
|
||||
|
||||
import com.github.gtache.autosubtitle.gui.impl.CombinedResourceBundle;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class TestGuiCoreModule {
|
||||
|
||||
@Test
|
||||
void testBundle() {
|
||||
assertInstanceOf(CombinedResourceBundle.class, GuiCoreModule.providesBundle());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPlayImage() {
|
||||
assertTrue(GuiCoreModule.providesPlayImage().length > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPauseImage() {
|
||||
assertTrue(GuiCoreModule.providesPauseImage().length > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFontFamily() {
|
||||
assertEquals("Arial", GuiCoreModule.providesFontFamily());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFontSize() {
|
||||
assertEquals(12, GuiCoreModule.providesFontSize());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
a=one
|
||||
b=two
|
||||
c=three
|
||||
@@ -0,0 +1,2 @@
|
||||
a=two
|
||||
d=one
|
||||
@@ -0,0 +1,2 @@
|
||||
a=zwei
|
||||
d=eins
|
||||
@@ -0,0 +1,2 @@
|
||||
a=deux
|
||||
d=un
|
||||
@@ -0,0 +1,3 @@
|
||||
a=eins
|
||||
b=zwei
|
||||
c=drei
|
||||
@@ -0,0 +1,3 @@
|
||||
a=un
|
||||
b=deux
|
||||
c=trois
|
||||
Reference in New Issue
Block a user