From 6bd2d2c4b967886680d5ef69107072963d8f36ba Mon Sep 17 00:00:00 2001 From: KHobbits Date: Mon, 13 Aug 2012 02:32:45 +0100 Subject: Try and prevent 'corrupt' messages files from breaking essentials. --- Essentials/src/com/earth2me/essentials/I18n.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/I18n.java b/Essentials/src/com/earth2me/essentials/I18n.java index 97d500a6a..c00180087 100644 --- a/Essentials/src/com/earth2me/essentials/I18n.java +++ b/Essentials/src/com/earth2me/essentials/I18n.java @@ -70,7 +70,8 @@ public class I18n implements II18n public static String _(final String string, final Object... objects) { - if (instance == null) { + if (instance == null) + { return ""; } if (objects.length == 0) @@ -85,11 +86,20 @@ public class I18n implements II18n public String format(final String string, final Object... objects) { - final String format = translate(string); + String format = translate(string); MessageFormat messageFormat = messageFormatCache.get(format); if (messageFormat == null) { - messageFormat = new MessageFormat(format); + try + { + messageFormat = new MessageFormat(format); + } + catch (IllegalArgumentException e) + { + ess.getLogger().log(Level.SEVERE, "Invalid Translation key for '" + string + "': " + e.getMessage()); + format = format.replaceAll("\\{(\\D*?)\\}", "\\[$1\\]"); + messageFormat = new MessageFormat(format); + } messageFormatCache.put(format, messageFormat); } return messageFormat.format(objects); -- cgit v1.2.3