From 30b2e5008bb5a32ad6ca35070c3069ea6c626a5d Mon Sep 17 00:00:00 2001 From: Zach Bruggeman Date: Mon, 29 Apr 2013 17:23:48 -0700 Subject: [PATCH] Add ResourceBundle localization --- .../java/net/md_5/bungee/api/ProxyServer.java | 7 +++++++ .../src/main/java/net/md_5/bungee/BungeeCord.java | 15 +++++++++++++-- .../md_5/bungee/connection/DownstreamBridge.java | 2 +- proxy/src/main/resources/messages_en.properties | 3 +++ 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 proxy/src/main/resources/messages_en.properties diff --git a/api/src/main/java/net/md_5/bungee/api/ProxyServer.java b/api/src/main/java/net/md_5/bungee/api/ProxyServer.java index d556869e..88cc389f 100644 --- a/api/src/main/java/net/md_5/bungee/api/ProxyServer.java +++ b/api/src/main/java/net/md_5/bungee/api/ProxyServer.java @@ -49,6 +49,13 @@ public abstract class ProxyServer */ public abstract String getVersion(); + /** + * Gets a localized string from the .properties file. + * + * @return the localized string + */ + public abstract String getTranslation( String name ); + /** * Gets the main logger which can be used as a suitable replacement for * {@link System#out} and {@link System#err}. diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java index e2d51b61..48bb259b 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -24,6 +24,7 @@ import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Map; +import java.util.ResourceBundle; import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.ConcurrentHashMap; @@ -75,6 +76,10 @@ public class BungeeCord extends ProxyServer * Configuration. */ public final Configuration config = new Configuration(); + /** + * Localization bundle. + */ + public final ResourceBundle bundle = ResourceBundle.getBundle( "messages_en" ); /** * Thread pools. */ @@ -272,7 +277,7 @@ public class BungeeCord extends ProxyServer getLogger().info( "Disconnecting " + connections.size() + " connections" ); for ( UserConnection user : connections.values() ) { - user.disconnect( "Proxy restarting, brb." ); + user.disconnect( getTranslation( "restart" ) ); } getLogger().info( "Closing IO threads" ); @@ -290,7 +295,7 @@ public class BungeeCord extends ProxyServer getScheduler().cancel( plugin ); } - getLogger().info( "Thank you and goodbye" ); + getLogger().info( getTranslation( "end" ) ); System.exit( 0 ); } @@ -319,6 +324,12 @@ public class BungeeCord extends ProxyServer return ( BungeeCord.class.getPackage().getImplementationVersion() == null ) ? "unknown" : BungeeCord.class.getPackage().getImplementationVersion(); } + @Override + public String getTranslation(String name) + { + return bundle.getString( name ); + } + @Override public Logger getLogger() { diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java index 10b27ee7..f718830f 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java @@ -65,7 +65,7 @@ public class DownstreamBridge extends PacketHandler if ( !server.isObsolete() ) { - con.disconnect( "[Proxy] Lost connection to server D:" ); + con.disconnect( bungee.getTranslation( "lost_connection ") ); } } diff --git a/proxy/src/main/resources/messages_en.properties b/proxy/src/main/resources/messages_en.properties new file mode 100644 index 00000000..abdbad12 --- /dev/null +++ b/proxy/src/main/resources/messages_en.properties @@ -0,0 +1,3 @@ +restart: [Proxy] Proxy restarting. +lost_connection: [Proxy] Lost connection to server. +end: Thank you, and goodbye.