summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2012-08-13 02:32:45 +0100
committerKHobbits <rob@khobbits.co.uk>2012-08-13 02:32:45 +0100
commit6bd2d2c4b967886680d5ef69107072963d8f36ba (patch)
tree5b0e68e96df7b0252622070681f176244ec4c191
parentc40b23d80e6da27abaa2b0467320d385867e3000 (diff)
downloadEssentials-6bd2d2c4b967886680d5ef69107072963d8f36ba.tar
Essentials-6bd2d2c4b967886680d5ef69107072963d8f36ba.tar.gz
Essentials-6bd2d2c4b967886680d5ef69107072963d8f36ba.tar.lz
Essentials-6bd2d2c4b967886680d5ef69107072963d8f36ba.tar.xz
Essentials-6bd2d2c4b967886680d5ef69107072963d8f36ba.zip
Try and prevent 'corrupt' messages files from breaking essentials.
-rw-r--r--Essentials/src/com/earth2me/essentials/I18n.java16
1 files 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);