De-flexing: created our own ResourceBundle, ditched Locale from MesageManager
(it doesn't do jack right now anyway) git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4592 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -21,8 +21,6 @@
|
|||||||
|
|
||||||
package com.threerings.util {
|
package com.threerings.util {
|
||||||
|
|
||||||
import mx.resources.ResourceBundle;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
|
|||||||
@@ -21,10 +21,9 @@
|
|||||||
|
|
||||||
package com.threerings.util {
|
package com.threerings.util {
|
||||||
|
|
||||||
import mx.managers.ISystemManager;
|
//import mx.managers.ISystemManager;
|
||||||
|
//
|
||||||
import mx.resources.Locale;
|
//import mx.resources.Locale;
|
||||||
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
|
||||||
@@ -61,36 +60,36 @@ 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 (sysMgr :ISystemManager)
|
public function MessageManager ()
|
||||||
{
|
{
|
||||||
// use the default locale
|
// // use the default locale
|
||||||
_locale = Locale.getCurrent(sysMgr);
|
// _locale = Locale.getCurrent(sysMgr);
|
||||||
|
|
||||||
// load up the global bundle
|
// load up the global bundle
|
||||||
_global = getBundle(GLOBAL_BUNDLE);
|
_global = getBundle(GLOBAL_BUNDLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Get the locale that is being used to translate messages.
|
// * Get the locale that is being used to translate messages.
|
||||||
* This may be useful if using standard translations, for example
|
// * This may be useful if using standard translations, for example
|
||||||
* new SimpleDateFormat("EEEE", getLocale()) to get the name of a weekday
|
// * new SimpleDateFormat("EEEE", getLocale()) to get the name of a weekday
|
||||||
* that matches the language being used for all other client translations.
|
// * that matches the language being used for all other client translations.
|
||||||
*/
|
// */
|
||||||
public function getLocale () :Locale
|
// public function getLocale () :Locale
|
||||||
{
|
// {
|
||||||
return _locale;
|
// return _locale;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Sets the locale to the specified locale. Subsequent message bundles
|
// * Sets the locale to the specified locale. Subsequent message bundles
|
||||||
* fetched via the message manager will use the new locale. The
|
// * fetched via the message manager will use the new locale. The
|
||||||
* message bundle cache will also be cleared.
|
// * message bundle cache will also be cleared.
|
||||||
*/
|
// */
|
||||||
public function setLocale (locale :Locale) :void
|
// public function setLocale (locale :Locale) :void
|
||||||
{
|
// {
|
||||||
_locale = locale;
|
// _locale = locale;
|
||||||
_cache.clear();
|
// _cache.clear();
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the message bundle for the specified path. If no bundle can
|
* Fetches the message bundle for the specified path. If no bundle can
|
||||||
@@ -154,8 +153,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 :Locale;
|
||||||
|
|
||||||
/** A cache of instantiated message bundles. */
|
/** A cache of instantiated message bundles. */
|
||||||
protected var _cache :HashMap = new HashMap();
|
protected var _cache :HashMap = new HashMap();
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user