Whitespace
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6025 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -55,7 +55,6 @@ public class DefaultMap<K, V> extends ForwardingMap<K, V>
|
||||
return newMap(delegate, creator);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a Function that makes instances of the supplied class (using its no-args
|
||||
* constructor) as default values.
|
||||
|
||||
@@ -33,19 +33,17 @@ import com.samskivert.util.StringUtil;
|
||||
import static com.threerings.NaryaLog.log;
|
||||
|
||||
/**
|
||||
* A message bundle provides an easy mechanism by which to obtain
|
||||
* translated message strings from a resource bundle. It uses the {@link
|
||||
* MessageFormat} class to substitute arguments into the translation
|
||||
* strings. Message bundles would generally be obtained via the {@link
|
||||
* MessageManager}, but could be constructed individually if so desired.
|
||||
* A message bundle provides an easy mechanism by which to obtain translated message strings from
|
||||
* a resource bundle. It uses the {@link MessageFormat} class to substitute arguments into the
|
||||
* translation strings. Message bundles would generally be obtained via the {@link MessageManager},
|
||||
* but could be constructed individually if so desired.
|
||||
*/
|
||||
public class MessageBundle
|
||||
{
|
||||
/**
|
||||
* 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 {@link #xlate}).
|
||||
* 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 {@link #xlate}).
|
||||
*/
|
||||
public static String taint (Object text)
|
||||
{
|
||||
@@ -53,8 +51,8 @@ public class MessageBundle
|
||||
}
|
||||
|
||||
/**
|
||||
* Composes a message key with a single argument. The message can
|
||||
* subsequently be translated in a single call using {@link #xlate}.
|
||||
* Composes a message key with a single argument. The message can subsequently be translated
|
||||
* in a single call using {@link #xlate}.
|
||||
*/
|
||||
public static String compose (String key, Object arg)
|
||||
{
|
||||
@@ -62,8 +60,8 @@ public class MessageBundle
|
||||
}
|
||||
|
||||
/**
|
||||
* Composes a message key with an array of arguments. The message can
|
||||
* subsequently be translated in a single call using {@link #xlate}.
|
||||
* Composes a message key with an array of arguments. The message can subsequently be
|
||||
* translated in a single call using {@link #xlate}.
|
||||
*/
|
||||
public static String compose (String key, Object... args)
|
||||
{
|
||||
@@ -71,8 +69,8 @@ public class MessageBundle
|
||||
}
|
||||
|
||||
/**
|
||||
* Composes a message key with an array of arguments. The message can
|
||||
* subsequently be translated in a single call using {@link #xlate}.
|
||||
* Composes a message key with an array of arguments. The message can subsequently be
|
||||
* translated in a single call using {@link #xlate}.
|
||||
*/
|
||||
public static String compose (String key, String... args)
|
||||
{
|
||||
@@ -80,9 +78,8 @@ public class MessageBundle
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenience method for calling {@link #compose(String,Object[])}
|
||||
* with an array of arguments that will be automatically tainted (see
|
||||
* {@link #taint}).
|
||||
* A convenience method for calling {@link #compose(String,Object[])} with an array of
|
||||
* arguments that will be automatically tainted (see {@link #taint}).
|
||||
*/
|
||||
public static String tcompose (String key, Object... args)
|
||||
{
|
||||
@@ -106,9 +103,8 @@ public class MessageBundle
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenience method for calling {@link #compose(String,String[])}
|
||||
* with an array of arguments that will be automatically tainted (see
|
||||
* {@link #taint}).
|
||||
* A convenience method for calling {@link #compose(String,String[])} with an array of
|
||||
* arguments that will be automatically tainted (see {@link #taint}).
|
||||
*/
|
||||
public static String tcompose (String key, String... args)
|
||||
{
|
||||
@@ -116,9 +112,8 @@ public class MessageBundle
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
public static String qualify (String bundle, String key)
|
||||
{
|
||||
@@ -136,8 +131,7 @@ public class MessageBundle
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unqualified portion of the key from a fully qualified
|
||||
* message key.
|
||||
* Returns the unqualified portion of the key from a fully qualified message key.
|
||||
*
|
||||
* @see #qualify
|
||||
*/
|
||||
@@ -147,9 +141,8 @@ public class MessageBundle
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the message bundle which will obtain localized messages
|
||||
* from the supplied resource bundle. The path is provided purely for
|
||||
* reporting purposes.
|
||||
* Initializes the message bundle which will obtain localized messages from the supplied
|
||||
* resource bundle. The path is provided purely for reporting purposes.
|
||||
*/
|
||||
public void init (MessageManager msgmgr, String path,
|
||||
ResourceBundle bundle, MessageBundle parent)
|
||||
@@ -161,11 +154,10 @@ public class MessageBundle
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the translation for the specified message key. No arguments
|
||||
* are substituted into the translated string. If a translation
|
||||
* message does not exist for the specified key, an error is logged
|
||||
* and the key itself is returned so that the caller need not worry
|
||||
* about handling a null response.
|
||||
* Obtains the translation for the specified message key. No arguments are substituted into
|
||||
* the translated string. If a translation message does not exist for the specified key, an
|
||||
* error is logged and the key itself is returned so that the caller need not worry about
|
||||
* handling a null response.
|
||||
*/
|
||||
public String get (String key)
|
||||
{
|
||||
@@ -180,11 +172,10 @@ public class MessageBundle
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all messages whose key starts with the specified prefix to the
|
||||
* supplied collection.
|
||||
* Adds all messages whose key starts with the specified prefix to the supplied collection.
|
||||
*
|
||||
* @param includeParent if true, messages from our parent bundle (and its
|
||||
* parent bundle, all the way up the chain will be included).
|
||||
* @param includeParent if true, messages from our parent bundle (and its parent bundle, all
|
||||
* the way up the chain will be included).
|
||||
*/
|
||||
public void getAll (String prefix, Collection<String> messages, boolean includeParent)
|
||||
{
|
||||
@@ -201,11 +192,11 @@ public class MessageBundle
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all keys for messages whose key starts with the specified prefix to the
|
||||
* supplied collection.
|
||||
* Adds all keys for messages whose key starts with the specified prefix to the supplied
|
||||
* collection.
|
||||
*
|
||||
* @param includeParent if true, messages from our parent bundle (and its
|
||||
* parent bundle, all the way up the chain will be included).
|
||||
* @param 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)
|
||||
{
|
||||
@@ -222,8 +213,7 @@ public class MessageBundle
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if we have a translation mapping for the supplied key,
|
||||
* false if not.
|
||||
* Returns true if we have a translation mapping for the supplied key, false if not.
|
||||
*/
|
||||
public boolean exists (String key)
|
||||
{
|
||||
@@ -238,14 +228,12 @@ public class MessageBundle
|
||||
return getResourceString(key, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a String from the resource bundle, or null if there was an
|
||||
* error.
|
||||
* Get a String from the resource bundle, or null if there was an error.
|
||||
*
|
||||
* @param key the resource key.
|
||||
* @param reportMissing whether or not the method should log an error
|
||||
* if the resource didn't exist.
|
||||
* @param reportMissing whether or not the method should log an error if the resource didn't
|
||||
* exist.
|
||||
*/
|
||||
public String getResourceString (String key, boolean reportMissing)
|
||||
{
|
||||
@@ -275,35 +263,25 @@ public class MessageBundle
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the translation for the specified message key. The
|
||||
* specified arguments are substituted into the translated string.
|
||||
* Obtains the translation for the specified message key. The specified arguments are
|
||||
* substituted into the translated string.
|
||||
*
|
||||
* <p> If the first argument in the array is an {@link Integer}
|
||||
* object, a translation will be selected accounting for plurality in
|
||||
* the following manner. Assume a message key of
|
||||
* <code>m.widgets</code>, the following translations should be
|
||||
* defined:
|
||||
* <pre>
|
||||
* m.widgets.0 = no widgets.
|
||||
* m.widgets.1 = {0} widget.
|
||||
* m.widgets.n = {0} widgets.
|
||||
* </pre>
|
||||
* <p> If the first argument in the array is an {@link Integer} object, a translation will be
|
||||
* selected accounting for plurality in the following manner. Assume a message key of
|
||||
* <code>m.widgets</code>, the following translations should be defined: <pre> m.widgets.0 =
|
||||
* no widgets. m.widgets.1 = {0} widget. m.widgets.n = {0} widgets. </pre>
|
||||
*
|
||||
* The specified argument is substituted into the translated string as
|
||||
* appropriate. Consider using:
|
||||
* The specified argument is substituted into the translated string as appropriate. Consider
|
||||
* using:
|
||||
*
|
||||
* <pre>
|
||||
* m.widgets.n = {0,number,integer} widgets.
|
||||
* </pre>
|
||||
* <pre> m.widgets.n = {0,number,integer} widgets. </pre>
|
||||
*
|
||||
* to obtain proper insertion of commas and dots as appropriate for
|
||||
* the locale.
|
||||
* to obtain proper insertion of commas and dots as appropriate for the locale.
|
||||
*
|
||||
* <p> See {@link 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.
|
||||
* <p> See {@link 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, Object... args)
|
||||
{
|
||||
@@ -319,8 +297,10 @@ public class MessageBundle
|
||||
String msg = getResourceString(key + suffix, false);
|
||||
|
||||
if (msg == null) {
|
||||
// Playing with fire: This only works because it's the same "" reference we return from getSuffix()
|
||||
// Don't try this at home. Keep out of reach of children. If swallowed, consult StringUtil.isBlank()
|
||||
// Playing with fire: This only works because it's the same "" reference we return
|
||||
// from getSuffix()
|
||||
// Don't try this at home. Keep out of reach of children. If swallowed, consult
|
||||
// StringUtil.isBlank()
|
||||
if (suffix != "") {
|
||||
// Try the original key
|
||||
msg = getResourceString(key, false);
|
||||
@@ -328,7 +308,7 @@ public class MessageBundle
|
||||
|
||||
if (msg == null) {
|
||||
log.warning("Missing translation message", "bundle", _path, "key", key,
|
||||
new Exception());
|
||||
new Exception());
|
||||
|
||||
// return something bogus
|
||||
return (key + StringUtil.toString(args));
|
||||
@@ -339,8 +319,8 @@ public class MessageBundle
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the translation for the specified message key. The
|
||||
* specified arguments are substituted into the translated string.
|
||||
* Obtains the translation for the specified message key. The specified arguments are
|
||||
* substituted into the translated string.
|
||||
*/
|
||||
public String get (String key, String... args)
|
||||
{
|
||||
@@ -348,9 +328,8 @@ public class MessageBundle
|
||||
}
|
||||
|
||||
/**
|
||||
* A helper function for {@link #get(String,Object[])} that allows us
|
||||
* to automatically perform plurality processing if our first argument
|
||||
* can be coaxed to an {@link Integer}.
|
||||
* A helper function for {@link #get(String,Object[])} that allows us to automatically perform
|
||||
* plurality processing if our first argument can be coaxed to an {@link Integer}.
|
||||
*/
|
||||
protected String getSuffix (Object[] args)
|
||||
{
|
||||
@@ -371,23 +350,20 @@ public class MessageBundle
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the translation for the specified compound message key. A
|
||||
* compound key contains the message key followed by a tab separated
|
||||
* list of message arguments which will be subsituted into the
|
||||
* translation string.
|
||||
* Obtains the translation for the specified compound message key. A compound key contains the
|
||||
* message key followed by a tab separated list of message arguments which will be subsituted
|
||||
* into the translation string.
|
||||
*
|
||||
* <p> See {@link 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.
|
||||
* <p> See {@link 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 xlate (String compoundKey)
|
||||
{
|
||||
// if this is a qualified key, we need to pass the buck to the
|
||||
// appropriate message bundle; we have to do it here because we
|
||||
// want the compound arguments of this key to be translated in the
|
||||
// context of the containing message bundle qualification
|
||||
// if this is a qualified key, we need to pass the buck to the appropriate message bundle;
|
||||
// we have to do it here because we want the compound arguments of this key to be
|
||||
// translated in the context of the containing message bundle qualification
|
||||
if (compoundKey.startsWith(MessageUtil.QUAL_PREFIX)) {
|
||||
MessageBundle qbundle = _msgmgr.getBundle(getBundle(compoundKey));
|
||||
return qbundle.xlate(getUnqualifiedKey(compoundKey));
|
||||
@@ -423,12 +399,10 @@ public class MessageBundle
|
||||
return "[bundle=" + _bundle + ", path=" + _path + "]";
|
||||
}
|
||||
|
||||
/** The message manager via whom we'll resolve fully qualified
|
||||
* translation strings. */
|
||||
/** The message manager via whom we'll resolve fully qualified translation strings. */
|
||||
protected MessageManager _msgmgr;
|
||||
|
||||
/** The path that identifies the resource bundle we are using to
|
||||
* obtain our messages. */
|
||||
/** The path that identifies the resource bundle we are using to obtain our messages. */
|
||||
protected String _path;
|
||||
|
||||
/** The resource bundle from which we obtain our messages. */
|
||||
|
||||
Reference in New Issue
Block a user