diff --git a/src/as/com/threerings/util/MessageBundle.as b/src/as/com/threerings/util/MessageBundle.as index 86504d328..3cd9d4ac1 100644 --- a/src/as/com/threerings/util/MessageBundle.as +++ b/src/as/com/threerings/util/MessageBundle.as @@ -21,8 +21,6 @@ package com.threerings.util { -import mx.resources.ResourceBundle; - /** * A message bundle provides an easy mechanism by which to obtain * translated message strings from a resource bundle. It uses the {@link diff --git a/src/as/com/threerings/util/MessageManager.as b/src/as/com/threerings/util/MessageManager.as index 38853e51e..56bf0a86f 100644 --- a/src/as/com/threerings/util/MessageManager.as +++ b/src/as/com/threerings/util/MessageManager.as @@ -21,10 +21,9 @@ package com.threerings.util { -import mx.managers.ISystemManager; - -import mx.resources.Locale; -import mx.resources.ResourceBundle; +//import mx.managers.ISystemManager; +// +//import mx.resources.Locale; /** * The message manager provides a thin wrapper around Java's built-in @@ -61,36 +60,36 @@ public class MessageManager * ResourceBundle#getBundle(String,Locale,ClassLoader)} for a more * detailed explanation of how resource bundle paths are resolved. */ - public function MessageManager (sysMgr :ISystemManager) + public function MessageManager () { - // use the default locale - _locale = Locale.getCurrent(sysMgr); +// // use the default locale +// _locale = Locale.getCurrent(sysMgr); // load up the global bundle _global = getBundle(GLOBAL_BUNDLE); } - /** - * Get the locale that is being used to translate messages. - * This may be useful if using standard translations, for example - * new SimpleDateFormat("EEEE", getLocale()) to get the name of a weekday - * that matches the language being used for all other client translations. - */ - public function getLocale () :Locale - { - return _locale; - } - - /** - * Sets the locale to the specified locale. Subsequent message bundles - * fetched via the message manager will use the new locale. The - * message bundle cache will also be cleared. - */ - public function setLocale (locale :Locale) :void - { - _locale = locale; - _cache.clear(); - } +// /** +// * Get the locale that is being used to translate messages. +// * This may be useful if using standard translations, for example +// * new SimpleDateFormat("EEEE", getLocale()) to get the name of a weekday +// * that matches the language being used for all other client translations. +// */ +// public function getLocale () :Locale +// { +// return _locale; +// } +// +// /** +// * Sets the locale to the specified locale. Subsequent message bundles +// * fetched via the message manager will use the new locale. The +// * message bundle cache will also be cleared. +// */ +// public function setLocale (locale :Locale) :void +// { +// _locale = locale; +// _cache.clear(); +// } /** * Fetches the message bundle for the specified path. If no bundle can @@ -154,8 +153,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 :Locale; /** A cache of instantiated message bundles. */ protected var _cache :HashMap = new HashMap(); diff --git a/src/as/com/threerings/util/ResourceBundle.as b/src/as/com/threerings/util/ResourceBundle.as new file mode 100644 index 000000000..e89aeb1d8 --- /dev/null +++ b/src/as/com/threerings/util/ResourceBundle.as @@ -0,0 +1,82 @@ +package com.threerings.util { + +import flash.system.ApplicationDomain; + +/** + * A non-flex version of ResourceBundle. + */ +public /*abstract*/ class ResourceBundle +{ + /** + * Get a resource bundle by name. + */ + public static function getResourceBundle ( + baseName :String, appDom :ApplicationDomain = null) :ResourceBundle + { + if (appDom == null) { + appDom = ApplicationDomain.currentDomain; + } + + var className :String = baseName + "_properties"; + if (appDom.hasDefinition(className)) { + var obj :Object = new (Class(appDom.getDefinition(className)))(); + if (obj is ResourceBundle) { + var rb :ResourceBundle = ResourceBundle(obj); + rb.initialize(baseName); + return rb; + } + } + + throw new Error("Could not find resource bundle " + baseName); + } + + /** + * Get a resource value as a String. + */ + public function getString (key :String) :String + { + return String(getObject(key)); + } + + /** + * Get a resouce value as the raw type contained within the content + * object. + */ + public function getObject (key :String) :Object + { + var val :Object = _content[key]; + if (val != null) { + return val; + } + throw new Error("Key '" + key + "' was not found in resource bundle '" + + _name + "'."); + } + + /** + * Internal initialization method. + */ + private function initialize (name :String) :void + { + _content = getContent(); + if (_content == null) { + throw new Error("No content found in resource bundle '" + name + "'."); + } + _name = name; + } + + /** + * Get the content of this resource bundle. + * You may override this to do custom stuff. + */ + protected function getContent () :Object + { + return null; + } + + /** The name of this bundle. */ + protected var _name :String; + + /** Contains resource bundle values. */ + protected var _content :Object; +} +}