Skip to content

Commit

Permalink
uhhh uhh config system stuff, ref #4447
Browse files Browse the repository at this point in the history
  • Loading branch information
quat1024 committed Dec 7, 2023
1 parent 792e046 commit 34aeb40
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/main/java/org/violetmoon/zeta/config/Definition.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -30,13 +31,14 @@ public Definition(String name, List<String> 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);
Expand All @@ -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<String, String> 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;
}
Expand Down

0 comments on commit 34aeb40

Please sign in to comment.