2025-09-16 11:47:15 +02:00
|
|
|
package nu.marginalia.language.config;
|
|
|
|
|
|
|
|
import nu.marginalia.WmsaHome;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.nio.file.StandardOpenOption;
|
|
|
|
|
|
|
|
sealed public interface LanguageConfigLocation {
|
2025-09-16 11:49:46 +02:00
|
|
|
InputStream findLanguageConfiguration() throws IOException;
|
2025-09-16 11:47:15 +02:00
|
|
|
|
|
|
|
final class Auto implements LanguageConfigLocation {
|
|
|
|
@Override
|
2025-09-16 11:49:46 +02:00
|
|
|
public InputStream findLanguageConfiguration() throws IOException {
|
2025-09-16 11:47:15 +02:00
|
|
|
Path filesystemPath = WmsaHome.getLangugeConfig();
|
|
|
|
if (Files.exists(filesystemPath)) {
|
|
|
|
return Files.newInputStream(filesystemPath, StandardOpenOption.READ);
|
|
|
|
}
|
|
|
|
if (Boolean.getBoolean("language.experimental")) {
|
|
|
|
return ClassLoader.getSystemResourceAsStream("languages-experimental.xml");
|
|
|
|
} else {
|
|
|
|
return ClassLoader.getSystemResourceAsStream("languages-default.xml");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final class Experimental implements LanguageConfigLocation {
|
|
|
|
@Override
|
2025-09-16 11:49:46 +02:00
|
|
|
public InputStream findLanguageConfiguration() throws IOException {
|
2025-09-16 11:47:15 +02:00
|
|
|
return ClassLoader.getSystemResourceAsStream("languages-experimental.xml");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final class Default implements LanguageConfigLocation {
|
|
|
|
|
|
|
|
@Override
|
2025-09-16 11:49:46 +02:00
|
|
|
public InputStream findLanguageConfiguration() throws IOException {
|
2025-09-16 11:47:15 +02:00
|
|
|
return ClassLoader.getSystemResourceAsStream("languages-default.xml");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|