From baa03108bca449720c0919ce5c0cf35c82b4e827 Mon Sep 17 00:00:00 2001 From: Christian Mesh Date: Sat, 9 Sep 2023 09:16:20 -0400 Subject: [PATCH] Combine multiple translation files instead of picking one --- src/main/java/cam72cam/mod/ModCore.java | 34 ++++++++++++++----------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/main/java/cam72cam/mod/ModCore.java b/src/main/java/cam72cam/mod/ModCore.java index 197e83c9..0174b420 100644 --- a/src/main/java/cam72cam/mod/ModCore.java +++ b/src/main/java/cam72cam/mod/ModCore.java @@ -323,24 +323,28 @@ public InputStream getResource(String resourcePath) throws IOException { // Magical Translations! ResourceLocation lang = toLang(resourcePath); if (Minecraft.getInstance().getResourceManager().hasResource(lang)) { - try (BufferedReader reader = new BufferedReader(new InputStreamReader(Minecraft.getInstance().getResourceManager().getResource(lang).getInputStream()))) { - List translations = new ArrayList<>(); - String line; - while ((line = reader.readLine()) != null) { - String[] splits = line.split("=", 2); - if (splits.length == 2) { - String key = splits[0]; - String value = splits[1]; - - translations.add(String.format("\"%s\": \"%s\"", key, value)); - translations.add(String.format("\"%s\": \"%s\"", key.replace(":", "."), value)); - translations.add(String.format("\"%s\": \"%s\"", key.replace(".name", ""), value)); - translations.add(String.format("\"%s\": \"%s\"", key.replace(".name", "").replace(":", "."), value)); + Map rawTranslations = new HashMap<>(); + for (IResource resource : Minecraft.getInstance().getResourceManager().getResources(lang)) { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream()))) { + String line; + while ((line = reader.readLine()) != null) { + String[] splits = line.split("=", 2); + if (splits.length == 2) { + rawTranslations.put(splits[0], splits[1]); + } } } - String output = "{" + String.join(",", translations) + "}"; - return new ByteArrayInputStream(output.getBytes(StandardCharsets.UTF_8)); } + List translations = new ArrayList<>(); + rawTranslations.forEach((key, value) -> { + translations.add(String.format("\"%s\": \"%s\"", key, value)); + translations.add(String.format("\"%s\": \"%s\"", key.replace(":", "."), value)); + translations.add(String.format("\"%s\": \"%s\"", key.replace(".name", ""), value)); + translations.add(String.format("\"%s\": \"%s\"", key.replace(".name", "").replace(":", "."), value)); + }); + String output = "{" + String.join(",", translations) + "}"; + ModCore.info("Created translation for %s : %s", resourcePath, output); + return new ByteArrayInputStream(output.getBytes(StandardCharsets.UTF_8)); } } return null;