Better handle TL failover.

This commit is contained in:
KHobbits 2014-05-05 14:48:25 +01:00
parent 01d03d5d41
commit 363aee70d5
2 changed files with 39 additions and 9 deletions

View file

@ -129,11 +129,11 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials
} }
i18n = new I18n(this); i18n = new I18n(this);
i18n.onEnable(); i18n.onEnable();
i18n.updateLocale("en");
LOGGER.log(Level.INFO, tl("usingTempFolderForTesting")); LOGGER.log(Level.INFO, tl("usingTempFolderForTesting"));
LOGGER.log(Level.INFO, dataFolder.toString()); LOGGER.log(Level.INFO, dataFolder.toString());
this.initialize(null, server, new PluginDescriptionFile(new FileReader(new File("src" + File.separator + "plugin.yml"))), dataFolder, null, null); this.initialize(null, server, new PluginDescriptionFile(new FileReader(new File("src" + File.separator + "plugin.yml"))), dataFolder, null, null);
settings = new Settings(this); settings = new Settings(this);
i18n.updateLocale("en");
userMap = new UserMap(this); userMap = new UserMap(this);
permissionsHandler = new PermissionsHandler(this, false); permissionsHandler = new PermissionsHandler(this, false);
Economy.setEss(this); Economy.setEss(this);

View file

@ -12,6 +12,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import net.ess3.api.IEssentials; import net.ess3.api.IEssentials;
import org.bukkit.Bukkit;
public class I18n implements net.ess3.api.II18n public class I18n implements net.ess3.api.II18n
@ -23,15 +24,27 @@ public class I18n implements net.ess3.api.II18n
private transient ResourceBundle customBundle; private transient ResourceBundle customBundle;
private transient ResourceBundle localeBundle; private transient ResourceBundle localeBundle;
private final transient ResourceBundle defaultBundle; private final transient ResourceBundle defaultBundle;
private final transient Map<String, MessageFormat> messageFormatCache = new HashMap<String, MessageFormat>(); private transient Map<String, MessageFormat> messageFormatCache = new HashMap<String, MessageFormat>();
private final transient IEssentials ess; private final transient IEssentials ess;
private static final Pattern NODOUBLEMARK = Pattern.compile("''"); private static final Pattern NODOUBLEMARK = Pattern.compile("''");
private static final ResourceBundle NULL_BUNDLE = new ResourceBundle()
{
public Enumeration<String> getKeys()
{
return null;
}
protected Object handleGetObject(String key)
{
return null;
}
};
public I18n(final IEssentials ess) public I18n(final IEssentials ess)
{ {
this.ess = ess; this.ess = ess;
customBundle = ResourceBundle.getBundle(MESSAGES, defaultLocale, new FileResClassLoader(I18n.class.getClassLoader(), ess)); customBundle = NULL_BUNDLE;
localeBundle = ResourceBundle.getBundle(MESSAGES, defaultLocale); localeBundle = NULL_BUNDLE;
defaultBundle = ResourceBundle.getBundle(MESSAGES, Locale.ENGLISH); defaultBundle = ResourceBundle.getBundle(MESSAGES, Locale.ENGLISH);
} }
@ -128,10 +141,27 @@ public class I18n implements net.ess3.api.II18n
currentLocale = new Locale(parts[0], parts[1], parts[2]); currentLocale = new Locale(parts[0], parts[1], parts[2]);
} }
ResourceBundle.clearCache(); ResourceBundle.clearCache();
messageFormatCache = new HashMap<String, MessageFormat>();
Logger.getLogger("Essentials").log(Level.INFO, String.format("Using locale %s", currentLocale.toString())); Logger.getLogger("Essentials").log(Level.INFO, String.format("Using locale %s", currentLocale.toString()));
customBundle = ResourceBundle.getBundle(MESSAGES, currentLocale, new FileResClassLoader(I18n.class.getClassLoader(), ess));
try
{
localeBundle = ResourceBundle.getBundle(MESSAGES, currentLocale); localeBundle = ResourceBundle.getBundle(MESSAGES, currentLocale);
} }
catch (MissingResourceException ex)
{
localeBundle = NULL_BUNDLE;
}
try
{
customBundle = ResourceBundle.getBundle(MESSAGES, currentLocale, new FileResClassLoader(I18n.class.getClassLoader(), ess));
}
catch (MissingResourceException ex)
{
customBundle = NULL_BUNDLE;
}
}
public static String capitalCase(final String input) public static String capitalCase(final String input)
{ {
@ -166,7 +196,7 @@ public class I18n implements net.ess3.api.II18n
{ {
} }
} }
return super.getResource(string); return null;
} }
@Override @Override
@ -183,7 +213,7 @@ public class I18n implements net.ess3.api.II18n
{ {
} }
} }
return super.getResourceAsStream(string); return null;
} }
} }
} }