added getResourceString() which actually gets the business from
the ResourceBundle, making this class easy to extend... git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1323 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: MessageBundle.java,v 1.9 2002/05/01 02:45:00 mdb Exp $
|
// $Id: MessageBundle.java,v 1.10 2002/05/01 03:39:13 ray Exp $
|
||||||
|
|
||||||
package com.threerings.util;
|
package com.threerings.util;
|
||||||
|
|
||||||
@@ -38,26 +38,31 @@ public class MessageBundle
|
|||||||
*/
|
*/
|
||||||
public String get (String key)
|
public String get (String key)
|
||||||
{
|
{
|
||||||
// if we were unable to resolve our resource bundle, we can't do
|
|
||||||
// any translations
|
|
||||||
if (_bundle == null) {
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if this string is tainted, we don't translate it, instead we
|
// if this string is tainted, we don't translate it, instead we
|
||||||
// simply remove the taint character and return it to the caller
|
// simply remove the taint character and return it to the caller
|
||||||
if (key.startsWith(TAINT_CHAR)) {
|
if (key.startsWith(TAINT_CHAR)) {
|
||||||
return key.substring(1);
|
return key.substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String msg = getResourceString(key);
|
||||||
|
return (msg != null) ? msg : key;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a String from the resource bundle, or null if there was an error.
|
||||||
|
*/
|
||||||
|
protected String getResourceString (String key)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
return _bundle.getString(key);
|
if (_bundle != null) {
|
||||||
|
return _bundle.getString(key);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (MissingResourceException mre) {
|
} catch (MissingResourceException mre) {
|
||||||
Log.warning("Missing translation message " +
|
Log.warning("Missing translation message " +
|
||||||
"[bundle=" + _path + ", key=" + key + "].");
|
"[bundle=" + _path + ", key=" + key + "].");
|
||||||
return key;
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -117,21 +122,9 @@ public class MessageBundle
|
|||||||
*/
|
*/
|
||||||
public String get (String key, Object[] args)
|
public String get (String key, Object[] args)
|
||||||
{
|
{
|
||||||
// if we were unable to resolve our resource bundle, we can't do
|
String msg = getResourceString(key);
|
||||||
// any translations
|
return (msg != null) ? MessageFormat.format(msg, args)
|
||||||
if (_bundle == null) {
|
: (key + StringUtil.toString(args));
|
||||||
return key + StringUtil.toString(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
String message = _bundle.getString(key);
|
|
||||||
return MessageFormat.format(message, args);
|
|
||||||
|
|
||||||
} catch (MissingResourceException mre) {
|
|
||||||
Log.warning("Missing translation message " +
|
|
||||||
"[bundle=" + _path + ", key=" + key + "].");
|
|
||||||
return key + StringUtil.toString(args);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user