From 34aeb403954c00cccfce007c28fb1afa544d31fe Mon Sep 17 00:00:00 2001 From: quat1024 Date: Wed, 6 Dec 2023 23:32:35 -0500 Subject: [PATCH] uhhh uhh config system stuff, ref #4447 --- .../violetmoon/zeta/config/Definition.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/violetmoon/zeta/config/Definition.java b/src/main/java/org/violetmoon/zeta/config/Definition.java index e889ec2edc..6a2aa6f284 100644 --- a/src/main/java/org/violetmoon/zeta/config/Definition.java +++ b/src/main/java/org/violetmoon/zeta/config/Definition.java @@ -5,6 +5,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Locale; import java.util.function.Function; import java.util.stream.Collectors; @@ -30,13 +31,14 @@ public Definition(String name, List comment, @Nullable SectionDefinition this.name = name; this.parent = parent; - //TODO lol + //TODO lol; mainly sanitizing it so it won't blow up when the forge config system reads me this.comment = comment.stream() .flatMap(s -> Arrays.stream(s.split("\n"))) - .filter(line -> !line.trim().isEmpty()).collect(Collectors.toList()); + .filter(line -> !line.trim().isEmpty()) + .collect(Collectors.toList()); if(parent == null) - path = Collections.emptyList(); //TODO: skipping the "root" SectionDefinition + path = Collections.emptyList(); //TODO: skipping the "root" SectionDefinition in a clumsy way else { path = new ArrayList<>(parent.path); path.add(name); @@ -52,14 +54,20 @@ public String commentToString() { return comment == null ? "" : String.join("\n", comment); } - //TODO: weird, should probably be moved to GUI code - note this is SHARED code so i cant directly use i18n + private static final boolean translationDebug = System.getProperty("zeta.configTranslations", null) != null; + + //note this is SHARED code, so i cant directly use i18n public final String getGuiDisplayName(Function i18nDotGet) { - String defName = this instanceof SectionDefinition ? name.replace("_", "") : name; - String transKey = "quark.config." + String.join(".", path) + "." + name.toLowerCase().replaceAll(" ", "_").replaceAll("[^A-Za-z0-9_]", "") + ".name"; + String transKey = path.stream() + .map(s -> s.toLowerCase(Locale.ROOT).replace(" ", "_").replaceAll("[^A-Za-z0-9_]", "")) + .collect(Collectors.joining(".", "quark.config.", ".name")); + + if(translationDebug) + return transKey; String localized = i18nDotGet.apply(transKey); - if(localized.isEmpty() || localized.equals(transKey)) - return defName; + if(localized.isEmpty() || localized.equals(transKey)) //no user-specified translation + return name; return localized; }