Voxel Klippen System weiter optimiert, Monolog System implementiert, Compiler Warnungen behoben
This commit is contained in:
81
blight-lang/src/main/java/de/blight/lang/AudioResolver.java
Normal file
81
blight-lang/src/main/java/de/blight/lang/AudioResolver.java
Normal file
@@ -0,0 +1,81 @@
|
||||
package de.blight.lang;
|
||||
|
||||
import de.blight.common.model.AudioReference;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/** Löst AudioReference-Keys zur Laufzeit in Dateipfade auf.
|
||||
* Liest {@code lang/audio_<lang>.properties} vom Classpath.
|
||||
* Gibt null zurück wenn kein Eintrag gefunden wird. */
|
||||
public class AudioResolver {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AudioResolver.class);
|
||||
private static final String BASE_NAME = "lang/audio";
|
||||
|
||||
private static AudioResolver instance;
|
||||
|
||||
private final ResourceBundle bundle;
|
||||
private final ResourceBundle fallback;
|
||||
|
||||
private AudioResolver(Locale locale) {
|
||||
ResourceBundle fb;
|
||||
try {
|
||||
fb = ResourceBundle.getBundle(BASE_NAME, Locale.ENGLISH);
|
||||
} catch (MissingResourceException e) {
|
||||
fb = null;
|
||||
}
|
||||
this.fallback = fb;
|
||||
|
||||
if (locale.equals(Locale.ENGLISH)) {
|
||||
this.bundle = fb;
|
||||
} else {
|
||||
ResourceBundle loaded;
|
||||
try {
|
||||
loaded = ResourceBundle.getBundle(BASE_NAME, locale);
|
||||
} catch (MissingResourceException e) {
|
||||
loaded = fb;
|
||||
}
|
||||
this.bundle = loaded;
|
||||
}
|
||||
}
|
||||
|
||||
public static void init(Locale locale) {
|
||||
instance = new AudioResolver(locale);
|
||||
}
|
||||
|
||||
public static AudioResolver get() {
|
||||
if (instance == null) {
|
||||
instance = new AudioResolver(Locale.ENGLISH);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
/** Gibt den Dateipfad für den Key zurück, oder null wenn nicht gesetzt. */
|
||||
public String resolve(AudioReference ref) {
|
||||
if (ref == null || ref.key() == null || ref.key().isBlank()) {
|
||||
return null;
|
||||
}
|
||||
return resolveKey(ref.key());
|
||||
}
|
||||
|
||||
public String resolveKey(String key) {
|
||||
if (key == null || key.isBlank()) return null;
|
||||
if (bundle != null) {
|
||||
try {
|
||||
String val = bundle.getString(key);
|
||||
if (!val.isBlank()) return val;
|
||||
} catch (MissingResourceException ignored) {}
|
||||
}
|
||||
if (fallback != null && fallback != bundle) {
|
||||
try {
|
||||
String val = fallback.getString(key);
|
||||
if (!val.isBlank()) return val;
|
||||
} catch (MissingResourceException ignored) {}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user