us.zuercher.gpx2map.i18n
Class Text

java.lang.Object
  extended by us.zuercher.gpx2map.i18n.Text

public class Text
extends Object

Text provides utility methods for retrieve localized text.

Author:
Stephan Zuercher

Field Summary
private  ResourceBundle bundle
          Text instance's configured resource bundle.
private static Text instance
          Singleton instance of Text.
private static Locale instanceLocale
          Locale used to configure the singleton.
 
Constructor Summary
private Text(Locale locale)
          Constructs a new Text instance.
 
Method Summary
 String get(String key, Object... parameters)
          Retrieves the string for the given key from the configured resource bundle and, optionally, performs message formatting on the on the string.
static Text getInstance()
          Retrieve the singleton instance of Text.
private  String keyToErrorResult(String key, Object... parameters)
          Converts a key and parameters in "key[parameters...]" format.
static void setInstanceLocale(Locale locale)
          Configures the singleton instance's locale.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

private static Text instance
Singleton instance of Text.


instanceLocale

private static Locale instanceLocale
Locale used to configure the singleton. May be changed before the singleton is instantiated via setInstanceLocale(Locale).


bundle

private final ResourceBundle bundle
Text instance's configured resource bundle.

Constructor Detail

Text

private Text(Locale locale)
Constructs a new Text instance.

Parameters:
locale - the locale to use for resource bundle naming
Method Detail

setInstanceLocale

public static void setInstanceLocale(Locale locale)
Configures the singleton instance's locale. May only be called before any call to getInstance(). The instance locale defaults to the system locale.

Parameters:
locale - new locale to use for singleton instance
Throws:
IllegalStateException - if getInstance() has already been called

getInstance

public static Text getInstance()
Retrieve the singleton instance of Text. The instance's locale may be set by calling setInstanceLocale(Locale) before calling this method.

Returns:
the singleton Text instance

get

public String get(String key,
                  Object... parameters)
Retrieves the string for the given key from the configured resource bundle and, optionally, performs message formatting on the on the string.

If the key is not found in the resource bundle, the key is returned.

If no parameters are given, the string from the resource bundle is returned unchanged.

If parameters are given, but the string from the resource bundle is not not a valid pattern, the key is returned.

Parameters:
key - the resource property key
parameters - parameters to apply to the resource value
Returns:
the string associated with the key, possibly formatted
See Also:
keyToErrorResult(String, Object[])

keyToErrorResult

private String keyToErrorResult(String key,
                                Object... parameters)
Converts a key and parameters in "key[parameters...]" format.

Parameters:
key - resource property key
parameters - parameters to apply to the resource value
Returns:
the key, followed by its parameters in square brackets