From f0311f3245e7db61660b83764d33727750ff2f17 Mon Sep 17 00:00:00 2001 From: FortressNebula Date: Sat, 5 Nov 2022 22:31:59 +0000 Subject: [PATCH] Add support for other mod ids in LangMerger --- .../create/foundation/data/LangMerger.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/data/LangMerger.java b/src/main/java/com/simibubi/create/foundation/data/LangMerger.java index ddbb9529d..9bbf8abe7 100644 --- a/src/main/java/com/simibubi/create/foundation/data/LangMerger.java +++ b/src/main/java/com/simibubi/create/foundation/data/LangMerger.java @@ -39,6 +39,8 @@ public class LangMerger implements DataProvider { static final String CATEGORY_HEADER = "\t\"_\": \"->------------------------] %s [------------------------<-\","; private DataGenerator gen; + private final String modid; + private final String displayName; private List mergedLangData; private Map> populatedLangData; @@ -47,8 +49,12 @@ public class LangMerger implements DataProvider { private List langIgnore; - public LangMerger(DataGenerator gen) { + public LangMerger(DataGenerator gen) { this(gen, Create.ID, "Create"); } + + public LangMerger(DataGenerator gen, String modid, String displayName) { this.gen = gen; + this.modid = modid; + this.displayName = displayName; this.mergedLangData = new ArrayList<>(); this.langIgnore = new ArrayList<>(); this.allLocalizedEntries = new HashMap<>(); @@ -78,7 +84,7 @@ public class LangMerger implements DataProvider { @Override public void run(HashCache cache) throws IOException { Path path = this.gen.getOutputFolder() - .resolve("assets/" + Create.ID + "/lang/" + "en_us.json"); + .resolve("assets/" + modid + "/lang/" + "en_us.json"); for (Pair pair : getAllLocalizationFiles()) { if (!pair.getRight() @@ -112,7 +118,7 @@ public class LangMerger implements DataProvider { for (Entry> localization : populatedLangData.entrySet()) { String key = localization.getKey(); Path populatedLangPath = this.gen.getOutputFolder() - .resolve("assets/" + Create.ID + "/lang/unfinished/" + key); + .resolve("assets/" + modid + "/lang/unfinished/" + key); save(cache, localization.getValue(), missingTranslationTally.get(key) .intValue(), populatedLangPath, "Populating " + key + " with missing entries..."); } @@ -180,7 +186,7 @@ public class LangMerger implements DataProvider { // Always put tooltips and ponder scenes in their own paragraphs if (key.endsWith(".tooltip")) return true; - if (key.startsWith("create.ponder") && key.endsWith(PonderScene.TITLE_KEY)) + if (key.startsWith(modid + ".ponder") && key.endsWith(PonderScene.TITLE_KEY)) return true; key = key.replaceFirst("\\.", ""); @@ -198,7 +204,7 @@ public class LangMerger implements DataProvider { private List> getAllLocalizationFiles() { ArrayList> list = new ArrayList<>(); - String filepath = "assets/" + Create.ID + "/lang/"; + String filepath = "assets/" + modid + "/lang/"; try (InputStream resourceStream = ClassLoader.getSystemResourceAsStream(filepath)) { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(resourceStream)); while (true) { @@ -250,7 +256,7 @@ public class LangMerger implements DataProvider { if (missingKeys != -1) builder.append("\t\"_\": \"Missing Localizations: " + missingKeys + "\",\n"); data.forEach(builder::append); - builder.append("\t\"_\": \"Thank you for translating Create!\"\n\n"); + builder.append("\t\"_\": \"Thank you for translating ").append(displayName).append("!\"\n\n"); builder.append("}"); return builder.toString(); }