Fallback to the fallback fallback

This commit is contained in:
KingRainbow44 2022-05-08 11:53:37 -04:00 committed by Melledy
parent 09801a1845
commit 137ea1e294

View File

@ -46,12 +46,15 @@ public final class Language {
private Language(String fileName, String fallback) { private Language(String fileName, String fallback) {
@Nullable JsonObject languageData = null; @Nullable JsonObject languageData = null;
try { InputStream file = Grasscutter.class.getResourceAsStream("/languages/" + fileName);
InputStream file = Grasscutter.class.getResourceAsStream("/languages/" + fileName); if(file == null) // Provided fallback language.
if(file == null) { file = Grasscutter.class.getResourceAsStream("/languages/" + fallback);
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 {
languageData = Grasscutter.getGsonFactory().fromJson(Utils.readFromInputStream(file), JsonObject.class); languageData = Grasscutter.getGsonFactory().fromJson(Utils.readFromInputStream(file), JsonObject.class);
} catch (Exception exception) { } catch (Exception exception) {
Grasscutter.getLogger().warn("Failed to load language file: " + fileName, exception); Grasscutter.getLogger().warn("Failed to load language file: " + fileName, exception);