Added code to allow the creation of custom message bundles to go along
with a particular bundle's translation files. Mainly so Ray can do his funny business with the pirate message translations. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1321 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: MessageBundle.java,v 1.8 2002/04/30 17:45:27 mdb Exp $
|
// $Id: MessageBundle.java,v 1.9 2002/05/01 02:45:00 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.util;
|
package com.threerings.util;
|
||||||
|
|
||||||
@@ -19,11 +19,11 @@ import com.samskivert.util.StringUtil;
|
|||||||
public class MessageBundle
|
public class MessageBundle
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructs a message bundle which will obtain localized messages
|
* Initializes the message bundle which will obtain localized messages
|
||||||
* from the supplied resource bundle. The path is provided purely for
|
* from the supplied resource bundle. The path is provided purely for
|
||||||
* reporting purposes.
|
* reporting purposes.
|
||||||
*/
|
*/
|
||||||
public MessageBundle (String path, ResourceBundle bundle)
|
public void init (String path, ResourceBundle bundle)
|
||||||
{
|
{
|
||||||
_path = path;
|
_path = path;
|
||||||
_bundle = bundle;
|
_bundle = bundle;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: MessageManager.java,v 1.2 2002/04/30 17:45:27 mdb Exp $
|
// $Id: MessageManager.java,v 1.3 2002/05/01 02:45:00 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.util;
|
package com.threerings.util;
|
||||||
|
|
||||||
@@ -8,6 +8,8 @@ import java.util.Locale;
|
|||||||
import java.util.MissingResourceException;
|
import java.util.MissingResourceException;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
import com.samskivert.util.StringUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The message manager provides a thin wrapper around Java's built-in
|
* The message manager provides a thin wrapper around Java's built-in
|
||||||
* localization support, supporting a policy of dividing up localization
|
* localization support, supporting a policy of dividing up localization
|
||||||
@@ -89,10 +91,32 @@ public class MessageManager
|
|||||||
"[path=" + fqpath + ", locale=" + _locale + "].");
|
"[path=" + fqpath + ", locale=" + _locale + "].");
|
||||||
}
|
}
|
||||||
|
|
||||||
// create our message bundle, cache it and return it (if we
|
// if the resource bundle contains a special resource, we'll
|
||||||
|
// interpret that as a derivation of MessageBundle to instantiate
|
||||||
|
// for handling that class
|
||||||
|
String mbclass = null;
|
||||||
|
if (rbundle != null) {
|
||||||
|
mbclass = rbundle.getString(MBUNDLE_CLASS_KEY);
|
||||||
|
}
|
||||||
|
if (!StringUtil.blank(mbclass)) {
|
||||||
|
try {
|
||||||
|
bundle = (MessageBundle)Class.forName(mbclass).newInstance();
|
||||||
|
} catch (Throwable t) {
|
||||||
|
Log.warning("Failure instantiating custom message bundle " +
|
||||||
|
"[mbclass=" + mbclass + ", error=" + t + "].");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if there was no custom class, or we failed to instantiate the
|
||||||
|
// custom class, use a standard message bundle
|
||||||
|
if (bundle == null) {
|
||||||
|
bundle = new MessageBundle();
|
||||||
|
}
|
||||||
|
|
||||||
|
// initialize our message bundle, cache it and return it (if we
|
||||||
// couldn't resolve the bundle, the message bundle will cope with
|
// couldn't resolve the bundle, the message bundle will cope with
|
||||||
// it's null resource bundle)
|
// it's null resource bundle)
|
||||||
bundle = new MessageBundle(path, rbundle);
|
bundle.init(path, rbundle);
|
||||||
_cache.put(path, bundle);
|
_cache.put(path, bundle);
|
||||||
return bundle;
|
return bundle;
|
||||||
}
|
}
|
||||||
@@ -105,4 +129,8 @@ public class MessageManager
|
|||||||
|
|
||||||
/** A cache of instantiated message bundles. */
|
/** A cache of instantiated message bundles. */
|
||||||
protected HashMap _cache = new HashMap();
|
protected HashMap _cache = new HashMap();
|
||||||
|
|
||||||
|
/** A key that can contain the classname of a custom message bundle
|
||||||
|
* class to be used to handle messages for a particular bundle. */
|
||||||
|
protected static final String MBUNDLE_CLASS_KEY = "msgbundle_class";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user