Updated to work with the revamped resource handling of flex 3.
We're supposed to use ResourceManager.getString(bundleName, rsrcName) and that will do cool locale chaining, but then we're looking up the bundle every time. We may want to revisit this in the future. (Cool chaining: we can compile the app with the local order as [ "jp_JP", "en_US" ], and then if we request the "b.buy" key from the "game" bundle, it will look in japanese for b.buy, but fall back to english if not found.) git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4945 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
package com.threerings.util {
|
package com.threerings.util {
|
||||||
|
|
||||||
import mx.resources.ResourceBundle;
|
import mx.resources.IResourceBundle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A message bundle provides an easy mechanism by which to obtain
|
* A message bundle provides an easy mechanism by which to obtain
|
||||||
@@ -38,7 +38,7 @@ public class MessageBundle
|
|||||||
* reporting purposes.
|
* reporting purposes.
|
||||||
*/
|
*/
|
||||||
public function init (
|
public function init (
|
||||||
msgmgr :MessageManager, path :String, bundle :ResourceBundle,
|
msgmgr :MessageManager, path :String, bundle :IResourceBundle,
|
||||||
parent :MessageBundle) :void
|
parent :MessageBundle) :void
|
||||||
{
|
{
|
||||||
_msgmgr = msgmgr;
|
_msgmgr = msgmgr;
|
||||||
@@ -100,12 +100,11 @@ public class MessageBundle
|
|||||||
protected function getResourceString (
|
protected function getResourceString (
|
||||||
key :String, reportMissing :Boolean = true) :String
|
key :String, reportMissing :Boolean = true) :String
|
||||||
{
|
{
|
||||||
try {
|
if (_bundle != null) {
|
||||||
if (_bundle != null) {
|
var val :Object = _bundle.content[key];
|
||||||
return _bundle.getString(key);
|
if (val != null) {
|
||||||
|
return String(val);
|
||||||
}
|
}
|
||||||
} catch (missingResource :Error) {
|
|
||||||
// fall through and try the parent
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we have a parent, try getting the string from them
|
// if we have a parent, try getting the string from them
|
||||||
@@ -413,7 +412,7 @@ public class MessageBundle
|
|||||||
protected var _path :String;
|
protected var _path :String;
|
||||||
|
|
||||||
/** The resource bundle from which we obtain our messages. */
|
/** The resource bundle from which we obtain our messages. */
|
||||||
protected var _bundle :ResourceBundle;
|
protected var _bundle :IResourceBundle;
|
||||||
|
|
||||||
/** Our parent bundle if we're not the global bundle. */
|
/** Our parent bundle if we're not the global bundle. */
|
||||||
protected var _parent :MessageBundle;
|
protected var _parent :MessageBundle;
|
||||||
|
|||||||
@@ -21,11 +21,9 @@
|
|||||||
|
|
||||||
package com.threerings.util {
|
package com.threerings.util {
|
||||||
|
|
||||||
//import mx.managers.ISystemManager;
|
import mx.resources.IResourceBundle;
|
||||||
//
|
import mx.resources.Locale;
|
||||||
//import mx.resources.Locale;
|
import mx.resources.ResourceManager;
|
||||||
|
|
||||||
import mx.resources.ResourceBundle;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The message manager provides a thin wrapper around Java's built-in
|
* The message manager provides a thin wrapper around Java's built-in
|
||||||
@@ -64,8 +62,8 @@ public class MessageManager
|
|||||||
*/
|
*/
|
||||||
public function MessageManager ()
|
public function MessageManager ()
|
||||||
{
|
{
|
||||||
// // use the default locale
|
// use the default locale
|
||||||
// _locale = Locale.getCurrent(sysMgr);
|
_locale = ResourceManager.getInstance().getLocales()[0];
|
||||||
|
|
||||||
// load up the global bundle
|
// load up the global bundle
|
||||||
_global = getBundle(GLOBAL_BUNDLE);
|
_global = getBundle(GLOBAL_BUNDLE);
|
||||||
@@ -111,33 +109,23 @@ 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 rbundle :ResourceBundle = null;
|
var rbundle :IResourceBundle =
|
||||||
try {
|
ResourceManager.getInstance().getResourceBundle(_locale, path);
|
||||||
rbundle = ResourceBundle.getResourceBundle(path);
|
|
||||||
} catch (mre :Error) {
|
|
||||||
Log.getLog(this).warning("Unable to resolve resource bundle " +
|
|
||||||
"[path=" + path + "].");
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the resource bundle contains a special resource, we'll
|
// if the resource bundle contains a special resource, we'll
|
||||||
// interpret that as a derivation of MessageBundle to instantiate
|
// interpret that as a derivation of MessageBundle to instantiate
|
||||||
// for handling that class
|
// for handling that class
|
||||||
if (rbundle != null) {
|
if (rbundle != null) {
|
||||||
var mbclass :String = null;
|
var mbclass :Object = rbundle.content[MBUNDLE_CLASS_KEY];
|
||||||
try {
|
if (mbclass != null) {
|
||||||
mbclass = rbundle.getString(MBUNDLE_CLASS_KEY);
|
try {
|
||||||
if (!StringUtil.isBlank(mbclass)) {
|
var clazz :Class = ClassUtil.getClassByName(String(mbclass));
|
||||||
try {
|
bundle = new clazz();
|
||||||
var clazz :Class = ClassUtil.getClassByName(mbclass);
|
} catch (ee :Error) {
|
||||||
bundle = new clazz();
|
Log.getLog(this).warning(
|
||||||
} catch (ee :Error) {
|
"Failure instantiating custom message bundle " +
|
||||||
Log.getLog(this).warning(
|
"[mbclass=" + mbclass + ", error=" + ee + "].");
|
||||||
"Failure instantiating custom message bundle " +
|
|
||||||
"[mbclass=" + mbclass + ", error=" + ee + "].");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (eee :Error) {
|
|
||||||
// nada
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,8 +143,8 @@ public class MessageManager
|
|||||||
return bundle;
|
return bundle;
|
||||||
}
|
}
|
||||||
|
|
||||||
// /** 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 :String;
|
||||||
|
|
||||||
/** 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