From da02f02777943e58073504a55e46c020a2d4a5d7 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Sun, 24 Feb 2008 02:48:37 +0000 Subject: [PATCH] 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 --- src/as/com/threerings/util/MessageBundle.as | 15 +++--- src/as/com/threerings/util/MessageManager.as | 48 ++++++++------------ 2 files changed, 25 insertions(+), 38 deletions(-) diff --git a/src/as/com/threerings/util/MessageBundle.as b/src/as/com/threerings/util/MessageBundle.as index 6c185af89..06ae102cb 100644 --- a/src/as/com/threerings/util/MessageBundle.as +++ b/src/as/com/threerings/util/MessageBundle.as @@ -21,7 +21,7 @@ package com.threerings.util { -import mx.resources.ResourceBundle; +import mx.resources.IResourceBundle; /** * A message bundle provides an easy mechanism by which to obtain @@ -38,7 +38,7 @@ public class MessageBundle * reporting purposes. */ public function init ( - msgmgr :MessageManager, path :String, bundle :ResourceBundle, + msgmgr :MessageManager, path :String, bundle :IResourceBundle, parent :MessageBundle) :void { _msgmgr = msgmgr; @@ -100,12 +100,11 @@ public class MessageBundle protected function getResourceString ( key :String, reportMissing :Boolean = true) :String { - try { - if (_bundle != null) { - return _bundle.getString(key); + if (_bundle != null) { + var val :Object = _bundle.content[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 @@ -413,7 +412,7 @@ public class MessageBundle protected var _path :String; /** 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. */ protected var _parent :MessageBundle; diff --git a/src/as/com/threerings/util/MessageManager.as b/src/as/com/threerings/util/MessageManager.as index a6099d9e8..16ab9446e 100644 --- a/src/as/com/threerings/util/MessageManager.as +++ b/src/as/com/threerings/util/MessageManager.as @@ -21,11 +21,9 @@ package com.threerings.util { -//import mx.managers.ISystemManager; -// -//import mx.resources.Locale; - -import mx.resources.ResourceBundle; +import mx.resources.IResourceBundle; +import mx.resources.Locale; +import mx.resources.ResourceManager; /** * The message manager provides a thin wrapper around Java's built-in @@ -64,8 +62,8 @@ public class MessageManager */ public function MessageManager () { -// // use the default locale -// _locale = Locale.getCurrent(sysMgr); + // use the default locale + _locale = ResourceManager.getInstance().getLocales()[0]; // load up the global bundle _global = getBundle(GLOBAL_BUNDLE); @@ -111,33 +109,23 @@ public class MessageManager } // if it's not cached, we'll need to resolve it - var rbundle :ResourceBundle = null; - try { - rbundle = ResourceBundle.getResourceBundle(path); - } catch (mre :Error) { - Log.getLog(this).warning("Unable to resolve resource bundle " + - "[path=" + path + "]."); - } + var rbundle :IResourceBundle = + ResourceManager.getInstance().getResourceBundle(_locale, path); // if the resource bundle contains a special resource, we'll // interpret that as a derivation of MessageBundle to instantiate // for handling that class if (rbundle != null) { - var mbclass :String = null; - try { - mbclass = rbundle.getString(MBUNDLE_CLASS_KEY); - if (!StringUtil.isBlank(mbclass)) { - try { - var clazz :Class = ClassUtil.getClassByName(mbclass); - bundle = new clazz(); - } catch (ee :Error) { - Log.getLog(this).warning( - "Failure instantiating custom message bundle " + - "[mbclass=" + mbclass + ", error=" + ee + "]."); - } + var mbclass :Object = rbundle.content[MBUNDLE_CLASS_KEY]; + if (mbclass != null) { + try { + var clazz :Class = ClassUtil.getClassByName(String(mbclass)); + bundle = new clazz(); + } catch (ee :Error) { + Log.getLog(this).warning( + "Failure instantiating custom message bundle " + + "[mbclass=" + mbclass + ", error=" + ee + "]."); } - } catch (eee :Error) { - // nada } } @@ -155,8 +143,8 @@ public class MessageManager return bundle; } -// /** The locale for which we're obtaining message bundles. */ -// protected var _locale :Locale; + /** The locale for which we're obtaining message bundles. */ + protected var _locale :String; /** A cache of instantiated message bundles. */ protected var _cache :HashMap = new HashMap();