Add ResourceBundle localization

This commit is contained in:
Zach Bruggeman 2013-04-29 17:23:48 -07:00 committed by md_5
parent 140830efe0
commit 30b2e5008b
4 changed files with 24 additions and 3 deletions

View File

@ -49,6 +49,13 @@ public abstract class ProxyServer
*/ */
public abstract String getVersion(); 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 * Gets the main logger which can be used as a suitable replacement for
* {@link System#out} and {@link System#err}. * {@link System#out} and {@link System#err}.

View File

@ -24,6 +24,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.ResourceBundle;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -75,6 +76,10 @@ public class BungeeCord extends ProxyServer
* Configuration. * Configuration.
*/ */
public final Configuration config = new Configuration(); public final Configuration config = new Configuration();
/**
* Localization bundle.
*/
public final ResourceBundle bundle = ResourceBundle.getBundle( "messages_en" );
/** /**
* Thread pools. * Thread pools.
*/ */
@ -272,7 +277,7 @@ public class BungeeCord extends ProxyServer
getLogger().info( "Disconnecting " + connections.size() + " connections" ); getLogger().info( "Disconnecting " + connections.size() + " connections" );
for ( UserConnection user : connections.values() ) for ( UserConnection user : connections.values() )
{ {
user.disconnect( "Proxy restarting, brb." ); user.disconnect( getTranslation( "restart" ) );
} }
getLogger().info( "Closing IO threads" ); getLogger().info( "Closing IO threads" );
@ -290,7 +295,7 @@ public class BungeeCord extends ProxyServer
getScheduler().cancel( plugin ); getScheduler().cancel( plugin );
} }
getLogger().info( "Thank you and goodbye" ); getLogger().info( getTranslation( "end" ) );
System.exit( 0 ); System.exit( 0 );
} }
@ -319,6 +324,12 @@ public class BungeeCord extends ProxyServer
return ( BungeeCord.class.getPackage().getImplementationVersion() == null ) ? "unknown" : BungeeCord.class.getPackage().getImplementationVersion(); return ( BungeeCord.class.getPackage().getImplementationVersion() == null ) ? "unknown" : BungeeCord.class.getPackage().getImplementationVersion();
} }
@Override
public String getTranslation(String name)
{
return bundle.getString( name );
}
@Override @Override
public Logger getLogger() public Logger getLogger()
{ {

View File

@ -65,7 +65,7 @@ public class DownstreamBridge extends PacketHandler
if ( !server.isObsolete() ) if ( !server.isObsolete() )
{ {
con.disconnect( "[Proxy] Lost connection to server D:" ); con.disconnect( bungee.getTranslation( "lost_connection ") );
} }
} }

View File

@ -0,0 +1,3 @@
restart: [Proxy] Proxy restarting.
lost_connection: [Proxy] Lost connection to server.
end: Thank you, and goodbye.