mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-09-06 04:58:00 +02:00
Try and prevent 'corrupt' messages files from breaking essentials.
This commit is contained in:
parent
c40b23d80e
commit
6bd2d2c4b9
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user