Dieser Commit ist enthalten in:
Ursprung
8ee960e002
Commit
a78da0e2cf
@ -33,6 +33,7 @@ import java.io.InputStream;
|
|||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
public class Message {
|
public class Message {
|
||||||
|
|
||||||
@ -59,18 +60,15 @@ public class Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static SteamwarResourceBundle getOrCreateSingle(String name, String cacheKey) {
|
private static SteamwarResourceBundle getOrCreateSingle(String name, String cacheKey) {
|
||||||
if (bundles.containsKey(cacheKey)) {
|
return bundles.computeIfAbsent(cacheKey, s -> {
|
||||||
return bundles.get(cacheKey);
|
InputStream inputStream = Message.class.getResourceAsStream(name);
|
||||||
}
|
if(inputStream == null) return null;
|
||||||
InputStream inputStream = Message.class.getResourceAsStream(name);
|
try {
|
||||||
if(inputStream == null) return null;
|
return new SteamwarResourceBundle(inputStream);
|
||||||
try {
|
} catch (IOException e) {
|
||||||
SteamwarResourceBundle steamwarResourceBundle = new SteamwarResourceBundle(inputStream);
|
return null;
|
||||||
bundles.put(cacheKey, steamwarResourceBundle);
|
}
|
||||||
return steamwarResourceBundle;
|
});
|
||||||
} catch (IOException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ResourceBundle getResourceBundle(String baseName, Locale locale) {
|
private static ResourceBundle getResourceBundle(String baseName, Locale locale) {
|
||||||
@ -79,33 +77,23 @@ public class Message {
|
|||||||
}
|
}
|
||||||
String path = baseName.replace('.', '/');
|
String path = baseName.replace('.', '/');
|
||||||
|
|
||||||
SteamwarResourceBundle current = null;
|
AtomicReference<SteamwarResourceBundle> current = new AtomicReference<>();
|
||||||
SteamwarResourceBundle temp = getOrCreateSingle("/" + path + "_" + locale + ".properties", locale.toString());
|
apply(current, getOrCreateSingle("/" + path + "_" + locale.toString() + ".properties", locale.toString()), locale.toString());
|
||||||
if (temp != null) {
|
apply(current, getOrCreateSingle("/" + path + "_" + locale.getLanguage() + ".properties", locale.getLanguage()), locale.toString());
|
||||||
current = temp;
|
apply(current, getOrCreateSingle("/" + path + ".properties", ""), locale.toString());
|
||||||
bundles.put(locale.toString(), temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
temp = getOrCreateSingle("/" + path + "_" + locale.getLanguage() + ".properties", locale.getLanguage());
|
if (current.get() == null) throw new SecurityException("Could not find resource bundle for " + path);
|
||||||
if (current != null) current.setParent(temp);
|
|
||||||
if (temp != null) {
|
|
||||||
current = temp;
|
|
||||||
bundles.put(locale.toString(), temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
temp = getOrCreateSingle("/" + path + ".properties", "");
|
|
||||||
if (current != null) current.setParent(temp);
|
|
||||||
if (temp != null) {
|
|
||||||
current = temp;
|
|
||||||
bundles.put(locale.toString(), temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (current == null) {
|
|
||||||
throw new SecurityException("Could not find resource bundle for " + path);
|
|
||||||
}
|
|
||||||
return bundles.get(locale.toString());
|
return bundles.get(locale.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void apply(AtomicReference<SteamwarResourceBundle> current, SteamwarResourceBundle now, String bundleKey) {
|
||||||
|
if (current.get() != null) current.get().setParent(now);
|
||||||
|
if (now != null) {
|
||||||
|
current.set(now);
|
||||||
|
bundles.put(bundleKey, now);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static String parse(String message, boolean prefixed, Locale locale, Object... params){
|
private static String parse(String message, boolean prefixed, Locale locale, Object... params){
|
||||||
if(locale == null)
|
if(locale == null)
|
||||||
locale = Locale.getDefault();
|
locale = Locale.getDefault();
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren