Let's make these work correctly...

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4266 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-07-14 02:11:06 +00:00
parent 947db5851d
commit a9d0c5d285
2 changed files with 14 additions and 49 deletions
+8 -12
View File
@@ -23,6 +23,8 @@ package com.threerings.util {
import mx.resources.ResourceBundle;
import mx.utils.StringUtil;
/**
* A message bundle provides an easy mechanism by which to obtain
* translated message strings from a resource bundle. It uses the {@link
@@ -77,6 +79,8 @@ public class MessageBundle
// if we have a parent, try getting the string from them
if (_parent != null) {
trace("Trying to retrieve " + key + " from parent bundle: " +
_parent);
var value :String = _parent.getResourceString(key, false);
if (value != null) {
return value;
@@ -148,11 +152,12 @@ public class MessageBundle
if (msg == null) {
Log.getLog(this).warning("Missing translation message " +
"[bundle=" + _path + ", key=" + key + "].");
// return something bogus
return (key + args);
}
return (msg != null) ?
MessageFormat.format(escape(msg), args)
: (key + args);
return mx.utils.StringUtil.substitute(escape(msg), args);
}
/**
@@ -384,12 +389,3 @@ public class MessageBundle
protected static const QUAL_SEP :String = ":";
}
}
// TODO: figure out what we're going to do here
class MessageFormat
{
public static function format (msg :String, ... rest) :String
{
return msg + rest;
}
}
+6 -37
View File
@@ -61,20 +61,11 @@ public class MessageManager
* ResourceBundle#getBundle(String,Locale,ClassLoader)} for a more
* detailed explanation of how resource bundle paths are resolved.
*/
public function MessageManager (
resourcePrefix :String, sysMgr :ISystemManager)
public function MessageManager (sysMgr :ISystemManager)
{
// keep the prefix
_prefix = resourcePrefix;
// use the default locale
_locale = Locale.getCurrent(sysMgr);
// make sure the prefix ends with a dot
if (_prefix.charAt(_prefix.length - 1) != ".") {
_prefix += ".";
}
// load up the global bundle
_global = getBundle(GLOBAL_BUNDLE);
}
@@ -101,15 +92,6 @@ public class MessageManager
_cache.clear();
}
/**
* Allows a custom classloader to be configured for locating
* translation resources.
*/
// public void setClassLoader (ClassLoader loader)
// {
// _loader = loader;
// }
/**
* Fetches the message bundle for the specified path. If no bundle can
* be located with the specified path, a special bundle is returned
@@ -128,17 +110,12 @@ public class MessageManager
}
// if it's not cached, we'll need to resolve it
var fqpath :String = _prefix + path;
var rbundle :ResourceBundle = null;
try {
// if (_loader != null) {
// rbundle = ResourceBundle.getBundle(fqpath, _locale, _loader);
// } else {
rbundle = ResourceBundle.getResourceBundle(fqpath);
// }
rbundle = ResourceBundle.getResourceBundle(path);
} catch (mre :Error) {
Log.getLog(this).warning("Unable to resolve resource bundle " +
"[path=" + fqpath + "].");
"[path=" + path + "].");
}
// if the resource bundle contains a special resource, we'll
@@ -153,12 +130,10 @@ public class MessageManager
bundle = new clazz();
}
} catch (mre :Error) {
// nothing to worry about
} catch (t :Error) {
Log.getLog(this).warning("Failure instantiating custom message" +
" bundle [mbclass=" + mbclass + ", error=" + t + "].");
Log.getLog(this).warning(
"Failure instantiating custom message bundle " +
"[mbclass=" + mbclass + ", error=" + t + "].");
}
}
@@ -176,15 +151,9 @@ public class MessageManager
return bundle;
}
/** The prefix we prepend to resource paths prior to loading. */
protected var _prefix :String;
/** The locale for which we're obtaining message bundles. */
protected var _locale :Locale;
/** A custom class loader that we use to load resource bundles. */
// protected var _loader :ClassLoader;
/** A cache of instantiated message bundles. */
protected var _cache :HashMap = new HashMap();