forked from GeyserMC/Geyser
Moved loading and added default locale config option
This commit is contained in:
parent
b5ce83bbe2
commit
845c914492
9 changed files with 54 additions and 35 deletions
|
@ -101,6 +101,9 @@ public class GeyserBukkitConfiguration implements IGeyserConfiguration {
|
|||
return config.getBoolean("allow-third-party-capes", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultLocale() { return config.getString("default-locale", "en_us"); }
|
||||
|
||||
@Override
|
||||
public Path getFloodgateKeyFile() {
|
||||
return Paths.get(dataFolder.toString(), config.getString("floodgate-key-file", "public-key.pem"));
|
||||
|
|
|
@ -102,6 +102,9 @@ public class GeyserBungeeConfiguration implements IGeyserConfiguration {
|
|||
return config.getBoolean("allow-third-party-capes", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultLocale() { return config.getString("default-locale", "en_us"); }
|
||||
|
||||
@Override
|
||||
public Path getFloodgateKeyFile() {
|
||||
return Paths.get(dataFolder.toString(), config.getString("floodgate-key-file", "public-key.pem"));
|
||||
|
|
|
@ -105,6 +105,9 @@ public class GeyserSpongeConfiguration implements IGeyserConfiguration {
|
|||
return node.getNode("allow-third-party-capes").getBoolean(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultLocale() { return node.getNode("default-locale").getString("en_us"); }
|
||||
|
||||
@Override
|
||||
public Path getFloodgateKeyFile() {
|
||||
return Paths.get(dataFolder.toString(), node.getNode("floodgate-key-file").getString("public-key.pem"));
|
||||
|
|
|
@ -63,6 +63,9 @@ public class GeyserConfiguration implements IGeyserConfiguration {
|
|||
@JsonProperty("allow-third-party-capes")
|
||||
private boolean allowThirdPartyCapes;
|
||||
|
||||
@JsonProperty("default-locale")
|
||||
private String defaultLocale;
|
||||
|
||||
private MetricsInfo metrics;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -63,6 +63,9 @@ public class GeyserVelocityConfiguration implements IGeyserConfiguration {
|
|||
@JsonProperty("allow-third-party-capes")
|
||||
private boolean allowThirdPartyCapes;
|
||||
|
||||
@JsonProperty("default-locale")
|
||||
private String defaultLocale;
|
||||
|
||||
private MetricsInfo metrics;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -46,6 +46,8 @@ public interface IGeyserConfiguration {
|
|||
|
||||
boolean isAllowThirdPartyCapes();
|
||||
|
||||
String getDefaultLocale();
|
||||
|
||||
Path getFloodgateKeyFile();
|
||||
|
||||
IMetricsInfo getMetrics();
|
||||
|
|
|
@ -42,39 +42,6 @@ import java.io.InputStream;
|
|||
import java.util.*;
|
||||
|
||||
public class MessageUtils {
|
||||
private static final HashMap<String, HashMap<String, String>> LOCALE_MAPPINGS = new HashMap<>();
|
||||
|
||||
static {
|
||||
/* Load the language mappings */
|
||||
InputStream languagesStream = Toolbox.getResource("mappings/locales.json");
|
||||
JsonNode locales;
|
||||
try {
|
||||
locales = Toolbox.JSON_MAPPER.readTree(languagesStream);
|
||||
} catch (Exception e) {
|
||||
throw new AssertionError("Unable to load Java locale list", e);
|
||||
}
|
||||
|
||||
for (JsonNode localeNode : locales.get("locales")) {
|
||||
String currentLocale = localeNode.asText();
|
||||
|
||||
InputStream stream = Toolbox.getResource("mappings/lang/" + currentLocale + ".json");
|
||||
JsonNode lang;
|
||||
try {
|
||||
lang = Toolbox.JSON_MAPPER.readTree(stream);
|
||||
} catch (Exception e) {
|
||||
throw new AssertionError("Unable to load Java lang map for " + currentLocale, e);
|
||||
}
|
||||
|
||||
Iterator<Map.Entry<String, JsonNode>> langIterator = lang.fields();
|
||||
HashMap<String, String> langMap = new HashMap<>();
|
||||
while (langIterator.hasNext()) {
|
||||
Map.Entry<String, JsonNode> entry = langIterator.next();
|
||||
langMap.put(entry.getKey(), entry.getValue().asText());
|
||||
}
|
||||
|
||||
LOCALE_MAPPINGS.put(currentLocale.toLowerCase(), langMap);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> getTranslationParams(Message[] messages) {
|
||||
List<String> strings = new ArrayList<>();
|
||||
|
@ -138,9 +105,9 @@ public class MessageUtils {
|
|||
}
|
||||
|
||||
private static String getLocaleString(String messageText, String locale) {
|
||||
HashMap<String, String> localeStrings = LOCALE_MAPPINGS.get(locale.toLowerCase());
|
||||
HashMap<String, String> localeStrings = Toolbox.LOCALE_MAPPINGS.get(locale.toLowerCase());
|
||||
if (localeStrings == null)
|
||||
localeStrings = LOCALE_MAPPINGS.get("en_us");
|
||||
localeStrings = Toolbox.LOCALE_MAPPINGS.get(GeyserConnector.getInstance().getConfig().getDefaultLocale());
|
||||
|
||||
String newLocaleString = localeStrings.getOrDefault(messageText, messageText);
|
||||
|
||||
|
|
|
@ -52,6 +52,8 @@ public class Toolbox {
|
|||
|
||||
public static final Int2ObjectMap<ItemEntry> ITEM_ENTRIES = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
public static final HashMap<String, HashMap<String, String>> LOCALE_MAPPINGS = new HashMap<>();
|
||||
|
||||
static {
|
||||
/* Load biomes */
|
||||
InputStream biomestream = GeyserConnector.class.getClassLoader().getResourceAsStream("bedrock/biome_definitions.dat");
|
||||
|
@ -103,6 +105,36 @@ public class Toolbox {
|
|||
entry.getValue().get("bedrock_id").intValue(), entry.getValue().get("bedrock_data").intValue()));
|
||||
itemIndex++;
|
||||
}
|
||||
|
||||
/* Load the language mappings */
|
||||
stream = Toolbox.getResource("mappings/locales.json");
|
||||
JsonNode locales;
|
||||
try {
|
||||
locales = Toolbox.JSON_MAPPER.readTree(stream);
|
||||
} catch (Exception e) {
|
||||
throw new AssertionError("Unable to load Java locale list", e);
|
||||
}
|
||||
|
||||
for (JsonNode localeNode : locales.get("locales")) {
|
||||
String currentLocale = localeNode.asText();
|
||||
|
||||
InputStream localeStream = Toolbox.getResource("mappings/lang/" + currentLocale + ".json");
|
||||
JsonNode locale;
|
||||
try {
|
||||
locale = Toolbox.JSON_MAPPER.readTree(localeStream);
|
||||
} catch (Exception e) {
|
||||
throw new AssertionError("Unable to load Java lang map for " + currentLocale, e);
|
||||
}
|
||||
|
||||
Iterator<Map.Entry<String, JsonNode>> localeIterator = locale.fields();
|
||||
HashMap<String, String> langMap = new HashMap<>();
|
||||
while (localeIterator.hasNext()) {
|
||||
Map.Entry<String, JsonNode> entry = localeIterator.next();
|
||||
langMap.put(entry.getKey(), entry.getValue().asText());
|
||||
}
|
||||
|
||||
LOCALE_MAPPINGS.put(currentLocale.toLowerCase(), langMap);
|
||||
}
|
||||
}
|
||||
|
||||
public static InputStream getResource(String resource) {
|
||||
|
|
|
@ -57,6 +57,9 @@ general-thread-pool: 32
|
|||
# OptiFine capes, LabyMod capes, 5Zig capes and MinecraftCapes
|
||||
allow-third-party-capes: true
|
||||
|
||||
# The default locale if we dont have the one the client requested
|
||||
default-locale: en_us
|
||||
|
||||
# bStats is a stat tracker that is entirely anonymous and tracks only basic information
|
||||
# about Geyser, such as how many people are online, how many servers are using Geyser,
|
||||
# what OS is being used, etc. You can learn more about bStats here: https://bstats.org/.
|
||||
|
|
Loading…
Reference in a new issue