|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.threerings.util.MessageBundle
public class MessageBundle
A message bundle provides an easy mechanism by which to obtain translated message strings from
a resource bundle. It uses the MessageFormat class to substitute arguments into the
translation strings. Message bundles would generally be obtained via the MessageManager,
but could be constructed individually if so desired.
| Constructor Summary | |
|---|---|
MessageBundle()
|
|
| Method Summary | |
|---|---|
static String |
compose(String key,
Object... args)
Composes a message key with an array of arguments. |
static String |
compose(String key,
Object arg)
Composes a message key with a single argument. |
static String |
compose(String key,
String... args)
Composes a message key with an array of arguments. |
boolean |
exists(String key)
Returns true if we have a translation mapping for the supplied key, false if not. |
String |
get(String key)
Obtains the translation for the specified message key. |
String |
get(String key,
Object... args)
Obtains the translation for the specified message key. |
String |
get(String key,
String... args)
Obtains the translation for the specified message key. |
void |
getAll(String prefix,
Collection<String> messages,
boolean includeParent)
Adds all messages whose key starts with the specified prefix to the supplied collection. |
void |
getAllKeys(String prefix,
Collection<String> keys,
boolean includeParent)
Adds all keys for messages whose key starts with the specified prefix to the supplied collection. |
static String |
getBundle(String qualifiedKey)
Returns the bundle name from a fully qualified message key. |
String |
getResourceString(String key)
Get a String from the resource bundle, or null if there was an error. |
String |
getResourceString(String key,
boolean reportMissing)
Get a String from the resource bundle, or null if there was an error. |
String |
getSuffix(Object[] args)
A helper function for get(String,Object[]) that allows us to automatically perform
plurality processing if our first argument can be coaxed to an Integer. |
static String |
getUnqualifiedKey(String qualifiedKey)
Returns the unqualified portion of the key from a fully qualified message key. |
void |
init(MessageManager msgmgr,
String path,
ResourceBundle bundle,
MessageBundle parent)
Initializes the message bundle which will obtain localized messages from the supplied resource bundle. |
static String |
qualify(String bundle,
String key)
Returns a fully qualified message key which, when translated by some other bundle, will know to resolve and utilize the supplied bundle to translate this particular key. |
static String |
taint(Object text)
Call this to "taint" any string that has been entered by an entity outside the application so that the translation code knows not to attempt to translate this string when doing recursive translations (see xlate(java.lang.String)). |
static String |
tcompose(String key,
Object... args)
A convenience method for calling compose(String,Object[]) with an array of
arguments that will be automatically tainted (see taint(java.lang.Object)). |
static String |
tcompose(String key,
Object arg)
Required for backwards compatibility. |
static String |
tcompose(String key,
Object arg1,
Object arg2)
Required for backwards compatibility. |
static String |
tcompose(String key,
String... args)
A convenience method for calling compose(String,String[]) with an array of
arguments that will be automatically tainted (see taint(java.lang.Object)). |
String |
toString()
|
String |
xlate(String compoundKey)
Obtains the translation for the specified compound message key. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public MessageBundle()
| Method Detail |
|---|
public static String taint(Object text)
xlate(java.lang.String)).
public static String compose(String key,
Object arg)
xlate(java.lang.String).
public static String compose(String key,
Object... args)
xlate(java.lang.String).
public static String compose(String key,
String... args)
xlate(java.lang.String).
public static String tcompose(String key,
Object... args)
compose(String,Object[]) with an array of
arguments that will be automatically tainted (see taint(java.lang.Object)).
public static String tcompose(String key,
Object arg)
public static String tcompose(String key,
Object arg1,
Object arg2)
public static String tcompose(String key,
String... args)
compose(String,String[]) with an array of
arguments that will be automatically tainted (see taint(java.lang.Object)).
public static String qualify(String bundle,
String key)
public static String getBundle(String qualifiedKey)
qualify(java.lang.String, java.lang.String)public static String getUnqualifiedKey(String qualifiedKey)
qualify(java.lang.String, java.lang.String)
public void init(MessageManager msgmgr,
String path,
ResourceBundle bundle,
MessageBundle parent)
public String get(String key)
public void getAll(String prefix,
Collection<String> messages,
boolean includeParent)
includeParent - if true, messages from our parent bundle (and its parent bundle, all
the way up the chain will be included).
public void getAllKeys(String prefix,
Collection<String> keys,
boolean includeParent)
includeParent - if true, messages from our parent bundle (and its parent bundle, all
the way up the chain will be included).public boolean exists(String key)
public String getResourceString(String key)
public String getResourceString(String key,
boolean reportMissing)
key - the resource key.reportMissing - whether or not the method should log an error if the resource didn't
exist.
public String get(String key,
Object... args)
If the first argument in the array is an Integer object, a translation will be
selected accounting for plurality in the following manner. Assume a message key of
m.widgets, the following translations should be defined:
m.widgets.0 =
no widgets. m.widgets.1 = {0} widget. m.widgets.n = {0} widgets.
The specified argument is substituted into the translated string as appropriate. Consider
using:
m.widgets.n = {0,number,integer} widgets.
to obtain proper insertion of commas and dots as appropriate for the locale.
See MessageFormat for more information on how the substitution is performed. If
a translation message does not exist for the specified key, an error is logged and the key
itself (plus the arguments) is returned so that the caller need not worry about handling a
null response.
public String get(String key,
String... args)
public String getSuffix(Object[] args)
get(String,Object[]) that allows us to automatically perform
plurality processing if our first argument can be coaxed to an Integer.
public String xlate(String compoundKey)
See MessageFormat for more information on how the substitution is performed. If
a translation message does not exist for the specified key, an error is logged and the key
itself (plus the arguments) is returned so that the caller need not worry about handling a
null response.
public String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||