Not to choke if we can't resolve a resource bundle.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1320 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: MessageBundle.java,v 1.7 2002/03/27 21:52:41 mdb Exp $
|
||||
// $Id: MessageBundle.java,v 1.8 2002/04/30 17:45:27 mdb Exp $
|
||||
|
||||
package com.threerings.util;
|
||||
|
||||
@@ -38,6 +38,12 @@ public class MessageBundle
|
||||
*/
|
||||
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
|
||||
// simply remove the taint character and return it to the caller
|
||||
if (key.startsWith(TAINT_CHAR)) {
|
||||
@@ -111,6 +117,12 @@ public class MessageBundle
|
||||
*/
|
||||
public String get (String key, Object[] args)
|
||||
{
|
||||
// if we were unable to resolve our resource bundle, we can't do
|
||||
// any translations
|
||||
if (_bundle == null) {
|
||||
return key + StringUtil.toString(args);
|
||||
}
|
||||
|
||||
try {
|
||||
String message = _bundle.getString(key);
|
||||
return MessageFormat.format(message, args);
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
//
|
||||
// $Id: MessageManager.java,v 1.1 2002/01/29 20:44:35 mdb Exp $
|
||||
// $Id: MessageManager.java,v 1.2 2002/04/30 17:45:27 mdb Exp $
|
||||
|
||||
package com.threerings.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
@@ -80,13 +81,17 @@ public class MessageManager
|
||||
|
||||
// if it's not cached, we'll need to resolve it
|
||||
String fqpath = _prefix + path;
|
||||
ResourceBundle rbundle = ResourceBundle.getBundle(fqpath, _locale);
|
||||
if (rbundle == null) {
|
||||
ResourceBundle rbundle = null;
|
||||
try {
|
||||
rbundle = ResourceBundle.getBundle(fqpath, _locale);
|
||||
} catch (MissingResourceException mre) {
|
||||
Log.warning("Unable to resolve resource bundle " +
|
||||
"[path=" + fqpath + "].");
|
||||
"[path=" + fqpath + ", locale=" + _locale + "].");
|
||||
}
|
||||
|
||||
// create our message bundle, cache it and return it
|
||||
// create our message bundle, cache it and return it (if we
|
||||
// couldn't resolve the bundle, the message bundle will cope with
|
||||
// it's null resource bundle)
|
||||
bundle = new MessageBundle(path, rbundle);
|
||||
_cache.put(path, bundle);
|
||||
return bundle;
|
||||
|
||||
Reference in New Issue
Block a user