net.nand.util.i18n.mgr
Class StringManager

java.lang.Object
  extended by net.nand.util.i18n.mgr.StringManager
Direct Known Subclasses:
SOCStringManager

public class StringManager
extends java.lang.Object

String Manager for retrieving I18N localized text from .properties bundle files. Written for the JSettlers2 client by Luis A. Ramirez, extended and enhanced by Jeremy Monin.

Your app may want to extend this class if it has objects which want special formatting methods, or to provide and cache a single manager instance whose locale is set at startup.

Remember that bundle files are encoded not in UTF-8 but in ISO-8859-1:

You can use the net.nand.util.i18n.gui.PTEMain editor to compare and translate properties files conveniently side-by-side, without needing to deal with ISO-8859-1 unicode escapes.

Author:
lartkma

Field Summary
protected  java.util.ResourceBundle bundle
           
 
Constructor Summary
StringManager(java.lang.String bundlePath)
          Create a string manager for the bundles at bundlePath with the default locale.
StringManager(java.lang.String bundlePath, java.util.Locale loc)
          Create a string manager for the bundles at bundlePath with a certain Locale.
 
Method Summary
 java.lang.String get(java.lang.String key)
          Get a localized string (having no parameters) with the given key.
 java.lang.String get(java.lang.String key, java.lang.Object... arguments)
          Get and format a localized string (with parameters) with the given key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bundle

protected java.util.ResourceBundle bundle
Constructor Detail

StringManager

public StringManager(java.lang.String bundlePath)
Create a string manager for the bundles at bundlePath with the default locale. Remember that bundle files are encoded not in UTF-8 but in ISO-8859-1, see class javadoc.

Parameters:
bundlePath - Bundle path, will be retrieved with ResourceBundle.getBundle(String)

StringManager

public StringManager(java.lang.String bundlePath,
                     java.util.Locale loc)
Create a string manager for the bundles at bundlePath with a certain Locale. Remember that bundle files are encoded not in UTF-8 but in ISO-8859-1, see class javadoc.

Parameters:
bundlePath - Bundle path, will be retrieved with ResourceBundle.getBundle(String, Locale)
loc - Locale to use; not null
Method Detail

get

public final java.lang.String get(java.lang.String key)
                           throws java.util.MissingResourceException
Get a localized string (having no parameters) with the given key.

Parameters:
key - Key to use for string retrieval
Returns:
the localized string from the manager's bundle or one of its parents
Throws:
java.util.MissingResourceException - if no string can be found for key; this is a RuntimeException

get

public final java.lang.String get(java.lang.String key,
                                  java.lang.Object... arguments)
                           throws java.util.MissingResourceException
Get and format a localized string (with parameters) with the given key.

Parameters:
key - Key to use for string retrieval
arguments - Objects to use with {0}, {1}, etc in the localized string by calling MessageFormat.format(String, Object...).
Returns:
the localized formatted string from the manager's bundle or one of its parents
Throws:
java.util.MissingResourceException - if no string can be found for key; this is a RuntimeException