git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1388 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
snowleo 2011-05-09 02:48:30 +00:00
parent a314f16f90
commit e18cd69b5d

View File

@ -1,10 +1,8 @@
package com.earth2me.essentials; package com.earth2me.essentials;
import java.io.BufferedInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.MalformedURLException; import java.net.MalformedURLException;
@ -279,10 +277,12 @@ public class Util
public static double roundDouble(double d) public static double roundDouble(double d)
{ {
return Math.round(d*100.0)/100.0; return Math.round(d * 100.0) / 100.0;
} }
private static class ConfigClassLoader extends ClassLoader {
private static class ConfigClassLoader extends ClassLoader
{
private File dataFolder; private File dataFolder;
private ClassLoader cl; private ClassLoader cl;
@ -291,7 +291,7 @@ public class Util
this.dataFolder = dataFolder; this.dataFolder = dataFolder;
this.cl = cl; this.cl = cl;
} }
@Override @Override
public URL getResource(String string) public URL getResource(String string)
{ {
@ -364,29 +364,34 @@ public class Util
cl.setPackageAssertionStatus(string, bln); cl.setPackageAssertionStatus(string, bln);
} }
} }
private static final Locale defaultLocale = Locale.getDefault(); private static final Locale defaultLocale = Locale.getDefault();
public static Locale currentLocale = defaultLocale; public static Locale currentLocale = defaultLocale;
private static ResourceBundle bundle = ResourceBundle.getBundle("messages", defaultLocale); private static ResourceBundle bundle = ResourceBundle.getBundle("messages", defaultLocale);
public static String i18n(String string) { public static String i18n(String string)
{
return bundle.getString(string); return bundle.getString(string);
} }
public static String format(String string, Object... objects) { public static String format(String string, Object... objects)
{
MessageFormat mf = new MessageFormat(i18n(string)); MessageFormat mf = new MessageFormat(i18n(string));
return mf.format(objects); return mf.format(objects);
} }
public static void updateLocale(String loc, File dataFolder) { public static void updateLocale(String loc, File dataFolder)
if (loc == null || loc.isEmpty()) { {
if (loc == null || loc.isEmpty())
{
return; return;
} }
String[] parts = loc.split("_"); String[] parts = loc.split("_");
if (parts.length == 1) { if (parts.length == 1)
{
currentLocale = new Locale(parts[0]); currentLocale = new Locale(parts[0]);
} }
if (parts.length == 2) { if (parts.length == 2)
{
currentLocale = new Locale(parts[0], parts[1]); currentLocale = new Locale(parts[0], parts[1]);
} }
bundle = ResourceBundle.getBundle("messages", currentLocale, new ConfigClassLoader(dataFolder, Util.class.getClassLoader())); bundle = ResourceBundle.getBundle("messages", currentLocale, new ConfigClassLoader(dataFolder, Util.class.getClassLoader()));