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:
@@ -23,6 +23,8 @@ package com.threerings.util {
|
|||||||
|
|
||||||
import mx.resources.ResourceBundle;
|
import mx.resources.ResourceBundle;
|
||||||
|
|
||||||
|
import mx.utils.StringUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A message bundle provides an easy mechanism by which to obtain
|
* A message bundle provides an easy mechanism by which to obtain
|
||||||
* translated message strings from a resource bundle. It uses the {@link
|
* 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 we have a parent, try getting the string from them
|
||||||
if (_parent != null) {
|
if (_parent != null) {
|
||||||
|
trace("Trying to retrieve " + key + " from parent bundle: " +
|
||||||
|
_parent);
|
||||||
var value :String = _parent.getResourceString(key, false);
|
var value :String = _parent.getResourceString(key, false);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
return value;
|
return value;
|
||||||
@@ -148,11 +152,12 @@ public class MessageBundle
|
|||||||
if (msg == null) {
|
if (msg == null) {
|
||||||
Log.getLog(this).warning("Missing translation message " +
|
Log.getLog(this).warning("Missing translation message " +
|
||||||
"[bundle=" + _path + ", key=" + key + "].");
|
"[bundle=" + _path + ", key=" + key + "].");
|
||||||
|
|
||||||
|
// return something bogus
|
||||||
|
return (key + args);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (msg != null) ?
|
return mx.utils.StringUtil.substitute(escape(msg), args);
|
||||||
MessageFormat.format(escape(msg), args)
|
|
||||||
: (key + args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -384,12 +389,3 @@ public class MessageBundle
|
|||||||
protected static const QUAL_SEP :String = ":";
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -61,20 +61,11 @@ public class MessageManager
|
|||||||
* ResourceBundle#getBundle(String,Locale,ClassLoader)} for a more
|
* ResourceBundle#getBundle(String,Locale,ClassLoader)} for a more
|
||||||
* detailed explanation of how resource bundle paths are resolved.
|
* detailed explanation of how resource bundle paths are resolved.
|
||||||
*/
|
*/
|
||||||
public function MessageManager (
|
public function MessageManager (sysMgr :ISystemManager)
|
||||||
resourcePrefix :String, sysMgr :ISystemManager)
|
|
||||||
{
|
{
|
||||||
// keep the prefix
|
|
||||||
_prefix = resourcePrefix;
|
|
||||||
|
|
||||||
// use the default locale
|
// use the default locale
|
||||||
_locale = Locale.getCurrent(sysMgr);
|
_locale = Locale.getCurrent(sysMgr);
|
||||||
|
|
||||||
// make sure the prefix ends with a dot
|
|
||||||
if (_prefix.charAt(_prefix.length - 1) != ".") {
|
|
||||||
_prefix += ".";
|
|
||||||
}
|
|
||||||
|
|
||||||
// load up the global bundle
|
// load up the global bundle
|
||||||
_global = getBundle(GLOBAL_BUNDLE);
|
_global = getBundle(GLOBAL_BUNDLE);
|
||||||
}
|
}
|
||||||
@@ -101,15 +92,6 @@ public class MessageManager
|
|||||||
_cache.clear();
|
_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
|
* Fetches the message bundle for the specified path. If no bundle can
|
||||||
* be located with the specified path, a special bundle is returned
|
* 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
|
// if it's not cached, we'll need to resolve it
|
||||||
var fqpath :String = _prefix + path;
|
|
||||||
var rbundle :ResourceBundle = null;
|
var rbundle :ResourceBundle = null;
|
||||||
try {
|
try {
|
||||||
// if (_loader != null) {
|
rbundle = ResourceBundle.getResourceBundle(path);
|
||||||
// rbundle = ResourceBundle.getBundle(fqpath, _locale, _loader);
|
|
||||||
// } else {
|
|
||||||
rbundle = ResourceBundle.getResourceBundle(fqpath);
|
|
||||||
// }
|
|
||||||
} catch (mre :Error) {
|
} catch (mre :Error) {
|
||||||
Log.getLog(this).warning("Unable to resolve resource bundle " +
|
Log.getLog(this).warning("Unable to resolve resource bundle " +
|
||||||
"[path=" + fqpath + "].");
|
"[path=" + path + "].");
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the resource bundle contains a special resource, we'll
|
// if the resource bundle contains a special resource, we'll
|
||||||
@@ -153,12 +130,10 @@ public class MessageManager
|
|||||||
bundle = new clazz();
|
bundle = new clazz();
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (mre :Error) {
|
|
||||||
// nothing to worry about
|
|
||||||
|
|
||||||
} catch (t :Error) {
|
} catch (t :Error) {
|
||||||
Log.getLog(this).warning("Failure instantiating custom message" +
|
Log.getLog(this).warning(
|
||||||
" bundle [mbclass=" + mbclass + ", error=" + t + "].");
|
"Failure instantiating custom message bundle " +
|
||||||
|
"[mbclass=" + mbclass + ", error=" + t + "].");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,15 +151,9 @@ public class MessageManager
|
|||||||
return bundle;
|
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. */
|
/** The locale for which we're obtaining message bundles. */
|
||||||
protected var _locale :Locale;
|
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. */
|
/** A cache of instantiated message bundles. */
|
||||||
protected var _cache :HashMap = new HashMap();
|
protected var _cache :HashMap = new HashMap();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user