summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsnowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb>2011-05-09 02:47:19 +0000
committersnowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb>2011-05-09 02:47:19 +0000
commita314f16f9082f934ddeeb7936ee2ee7cf73f6768 (patch)
treef7989302436e137684107f905d901839687d06a0
parent0c334bc1e719ba0157905c44324eb2c3cd3bab9b (diff)
downloadEssentials-a314f16f9082f934ddeeb7936ee2ee7cf73f6768.tar
Essentials-a314f16f9082f934ddeeb7936ee2ee7cf73f6768.tar.gz
Essentials-a314f16f9082f934ddeeb7936ee2ee7cf73f6768.tar.lz
Essentials-a314f16f9082f934ddeeb7936ee2ee7cf73f6768.tar.xz
Essentials-a314f16f9082f934ddeeb7936ee2ee7cf73f6768.zip
[trunk] Translation of Essentials to other languages. This is just a start, many strings needs to be added.
Console doesn't show umlauts, but in game chat does. New config property: locale git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1387 e251c2fe-e539-e718-e476-b85c1f46cddb
-rw-r--r--Essentials/src/com/earth2me/essentials/Settings.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/Util.java123
-rw-r--r--Essentials/src/config.yml4
3 files changed, 128 insertions, 1 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java
index 58dfbcee5..112561a05 100644
--- a/Essentials/src/com/earth2me/essentials/Settings.java
+++ b/Essentials/src/com/earth2me/essentials/Settings.java
@@ -496,6 +496,6 @@ public class Settings implements IConf
public String getLocale()
{
- return config.getString("locale", "en_US");
+ return config.getString("locale", "");
}
}
diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java
index 79b194440..ed1150eb0 100644
--- a/Essentials/src/com/earth2me/essentials/Util.java
+++ b/Essentials/src/com/earth2me/essentials/Util.java
@@ -1,8 +1,21 @@
package com.earth2me.essentials;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.text.DecimalFormat;
+import java.text.MessageFormat;
import java.util.Calendar;
+import java.util.Enumeration;
import java.util.GregorianCalendar;
+import java.util.Locale;
+import java.util.ResourceBundle;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bukkit.Location;
@@ -268,4 +281,114 @@ public class Util
{
return Math.round(d*100.0)/100.0;
}
+
+ private static class ConfigClassLoader extends ClassLoader {
+ private File dataFolder;
+ private ClassLoader cl;
+
+ public ConfigClassLoader(File dataFolder, ClassLoader cl)
+ {
+ this.dataFolder = dataFolder;
+ this.cl = cl;
+ }
+
+ @Override
+ public URL getResource(String string)
+ {
+ File file = new File(dataFolder, string);
+ if (file.exists())
+ {
+ try
+ {
+ return file.toURI().toURL();
+ }
+ catch (MalformedURLException ex)
+ {
+ return cl.getResource(string);
+ }
+ }
+ return cl.getResource(string);
+ }
+
+ @Override
+ public synchronized void clearAssertionStatus()
+ {
+ cl.clearAssertionStatus();
+ }
+
+ @Override
+ public InputStream getResourceAsStream(String string)
+ {
+ File file = new File(dataFolder, string);
+ if (file.exists())
+ {
+ try
+ {
+ return new FileInputStream(file);
+ }
+ catch (FileNotFoundException ex)
+ {
+ return cl.getResourceAsStream(string);
+ }
+ }
+ return cl.getResourceAsStream(string);
+ }
+
+ @Override
+ public Enumeration<URL> getResources(String string) throws IOException
+ {
+ return cl.getResources(string);
+ }
+
+ @Override
+ public Class<?> loadClass(String string) throws ClassNotFoundException
+ {
+ return cl.loadClass(string);
+ }
+
+ @Override
+ public synchronized void setClassAssertionStatus(String string, boolean bln)
+ {
+ cl.setClassAssertionStatus(string, bln);
+ }
+
+ @Override
+ public synchronized void setDefaultAssertionStatus(boolean bln)
+ {
+ cl.setDefaultAssertionStatus(bln);
+ }
+
+ @Override
+ public synchronized void setPackageAssertionStatus(String string, boolean bln)
+ {
+ cl.setPackageAssertionStatus(string, bln);
+ }
+ }
+
+ private static final Locale defaultLocale = Locale.getDefault();
+ public static Locale currentLocale = defaultLocale;
+ private static ResourceBundle bundle = ResourceBundle.getBundle("messages", defaultLocale);
+
+ public static String i18n(String string) {
+ return bundle.getString(string);
+ }
+
+ public static String format(String string, Object... objects) {
+ MessageFormat mf = new MessageFormat(i18n(string));
+ return mf.format(objects);
+ }
+
+ public static void updateLocale(String loc, File dataFolder) {
+ if (loc == null || loc.isEmpty()) {
+ return;
+ }
+ String[] parts = loc.split("_");
+ if (parts.length == 1) {
+ currentLocale = new Locale(parts[0]);
+ }
+ if (parts.length == 2) {
+ currentLocale = new Locale(parts[0], parts[1]);
+ }
+ bundle = ResourceBundle.getBundle("messages", currentLocale, new ConfigClassLoader(dataFolder, Util.class.getClassLoader()));
+ }
}
diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml
index 5abd44543..a79f05ff6 100644
--- a/Essentials/src/config.yml
+++ b/Essentials/src/config.yml
@@ -185,6 +185,10 @@ sort-list-by-groups: false
# More output to the console
debug: false
+# Set the locale for all messages
+# If you don't set this, the default locale of the server will be used.
+#locale: de_DE
+
############################################################
# +------------------------------------------------------+ #
# | EssentialsHome | #