Some bits and bobs: there are ResourceBundle and Locale classes in the mx

package, use those. The ResourceBundle stuff is not quite working now due
to bugs in beta3, but I'll loop back to it later.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4126 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-05-18 22:39:01 +00:00
parent 8de54d537c
commit 0ac15b0e3c
6 changed files with 32 additions and 34 deletions
@@ -186,8 +186,8 @@ public class ChatDirector extends BasicDirector
var key :String = "c." + command;
if (msg.exists(key)) {
var tokens :Array = msg.get(key).split(/\s+/);
for (var ii :int = 0; ii < tokens.length; ii++) {
_handlers.put(tokens[ii], handler);
for each (var cmd :Object in tokens) {
_handlers.put(cmd, handler);
}
} else {
// fall back to just using the English command
@@ -276,8 +276,8 @@ public class ChatDirector extends BasicDirector
*/
public function dispatchMessage (message :ChatMessage) :void
{
for (var ii :int = 0; ii < _displays.length; ii++) {
(_displays.getItemAt(ii) as ChatDisplay).displayMessage(message);
for each (var display :ChatDisplay in _displays) {
display.displayMessage(message);
}
}
@@ -49,7 +49,7 @@ public class HelpHandler extends CommandHandler
var cmds :Array = possibleCmds.keys();
cmds.sort();
var cmdList :String = "";
for (var skey :String in cmds) {
for each (var skey :String in cmds) {
cmdList += " /" + skey;
}
return MessageBundle.tcompose("m.usage_help", cmdList);
+4 -2
View File
@@ -4,9 +4,11 @@ package com.threerings.util {
* An interface we can use to implement equals(), which is standard and
* very useful in Java.
*/
public interface Equalable {
public interface Equalable
{
/**
* Return true to see if this instance is equal to the specified object.
* Returns true to indicate that the specified object is equal to
* this instance.
*/
function equals (other :Object) :Boolean;
}
@@ -21,6 +21,8 @@
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
+21 -12
View File
@@ -21,6 +21,11 @@
package com.threerings.util {
import mx.managers.ISystemManager;
import mx.resources.Locale;
import mx.resources.ResourceBundle;
/**
* The message manager provides a thin wrapper around Java's built-in
* localization support, supporting a policy of dividing up localization
@@ -56,11 +61,15 @@ public class MessageManager
* ResourceBundle#getBundle(String,Locale,ClassLoader)} for a more
* detailed explanation of how resource bundle paths are resolved.
*/
public function MessageManager (resourcePrefix :String)
public function MessageManager (
resourcePrefix :String, sysMgr :ISystemManager)
{
// keep the prefix
_prefix = resourcePrefix;
// use the default locale
_locale = Locale.getCurrent(sysMgr);
// make sure the prefix ends with a dot
if (_prefix.charAt(_prefix.length - 1) != ".") {
_prefix += ".";
@@ -76,21 +85,21 @@ public class MessageManager
* new SimpleDateFormat("EEEE", getLocale()) to get the name of a weekday
* that matches the language being used for all other client translations.
*/
// public Locale getLocale ()
// {
// return _locale;
// }
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 void setLocale (Locale locale)
// {
// _locale = locale;
// _cache.clear();
// }
public function setLocale (locale :Locale) :void
{
_locale = locale;
_cache.clear();
}
/**
* Allows a custom classloader to be configured for locating
@@ -125,7 +134,7 @@ public class MessageManager
// if (_loader != null) {
// rbundle = ResourceBundle.getBundle(fqpath, _locale, _loader);
// } else {
rbundle = ResourceBundle.getBundle(fqpath);
rbundle = ResourceBundle.getResourceBundle(fqpath);
// }
} catch (mre :Error) {
Log.warning("Unable to resolve resource bundle " +
@@ -171,7 +180,7 @@ public class MessageManager
protected var _prefix :String;
/** 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;
@@ -1,15 +0,0 @@
package com.threerings.util {
public class ResourceBundle
{
public static function getBundle (path :String) :ResourceBundle
{
return new ResourceBundle();
}
public function getString (key :String) :String
{
return "TODO: resource:" + key;
}
}
}