Skip to content

Commit

Permalink
Skip invalid translation keys instead of crashing the game
Browse files Browse the repository at this point in the history
Closes #177
  • Loading branch information
thecatcore committed Jul 28, 2024
1 parent 20cc331 commit 668a5fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

public class ResourceManagerHelperImpl implements ResourceManagerHelper {
private static final ResourceManagerHelperImpl INSTANCE = new ResourceManagerHelperImpl();
private static final Logger LOGGER = Logger.get(LoggerImpl.API, "ResourceManagerHelperImpl");
public static final Logger LOGGER = Logger.get(LoggerImpl.API, "ResourceManagerHelperImpl");

private final Set<Identifier> addedListenerIds = new HashSet<>();
private final Set<IdentifiableResourceReloadListener> addedListeners = new LinkedHashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import net.legacyfabric.fabric.impl.resource.loader.ResourceManagerHelperImpl;

import org.apache.commons.io.Charsets;
import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -148,7 +151,13 @@ private void recursiveLoadTranslations(@NotNull String currentKey, JsonObject ob
key = entry.getKey();
}

this.translations.put(key, TOKEN_PATTERN.matcher(entry.getValue().getAsString()).replaceAll("%$1s"));
JsonElement value = entry.getValue();

if (value.isJsonPrimitive()) {
this.translations.put(key, TOKEN_PATTERN.matcher(value.getAsString()).replaceAll("%$1s"));
} else {
ResourceManagerHelperImpl.LOGGER.warn("Skipping translation key \"" + key + "\" with unsupported format " + value);
}
}
}
}
Expand Down

0 comments on commit 668a5fa

Please sign in to comment.