From 137ea1e294ec2581debb3a0b3cebf82ebcd8c06b Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Sun, 8 May 2022 11:53:37 -0400 Subject: [PATCH] Fallback to the fallback fallback --- src/main/java/emu/grasscutter/utils/Language.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/emu/grasscutter/utils/Language.java b/src/main/java/emu/grasscutter/utils/Language.java index 0af77adc1..d38907354 100644 --- a/src/main/java/emu/grasscutter/utils/Language.java +++ b/src/main/java/emu/grasscutter/utils/Language.java @@ -46,12 +46,15 @@ public final class Language { private Language(String fileName, String fallback) { @Nullable JsonObject languageData = null; + InputStream file = Grasscutter.class.getResourceAsStream("/languages/" + fileName); + if(file == null) // Provided fallback language. + file = Grasscutter.class.getResourceAsStream("/languages/" + fallback); + if(file == null) // Fallback the fallback language. + file = Grasscutter.class.getResourceAsStream("/languages/en-US.json"); + if(file == null) + throw new RuntimeException("Unable to load the primary, fallback, and 'en-US' language files."); + try { - InputStream file = Grasscutter.class.getResourceAsStream("/languages/" + fileName); - if(file == null) { - file = Grasscutter.class.getResourceAsStream("/languages/" + fallback); - } - languageData = Grasscutter.getGsonFactory().fromJson(Utils.readFromInputStream(file), JsonObject.class); } catch (Exception exception) { Grasscutter.getLogger().warn("Failed to load language file: " + fileName, exception);