From 9503d37d9031424ccea1ef11a295e6e7c59f5be1 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Wed, 1 May 2002 03:39:13 +0000 Subject: [PATCH] added getResourceString() which actually gets the business from the ResourceBundle, making this class easy to extend... git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1323 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../com/threerings/util/MessageBundle.java | 41 ++++++++----------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/src/java/com/threerings/util/MessageBundle.java b/src/java/com/threerings/util/MessageBundle.java index eb37c5bd0..3fd2957a7 100644 --- a/src/java/com/threerings/util/MessageBundle.java +++ b/src/java/com/threerings/util/MessageBundle.java @@ -1,5 +1,5 @@ // -// $Id: MessageBundle.java,v 1.9 2002/05/01 02:45:00 mdb Exp $ +// $Id: MessageBundle.java,v 1.10 2002/05/01 03:39:13 ray Exp $ package com.threerings.util; @@ -38,26 +38,31 @@ public class MessageBundle */ public String get (String key) { - // if we were unable to resolve our resource bundle, we can't do - // any translations - if (_bundle == null) { - return key; - } - // if this string is tainted, we don't translate it, instead we // simply remove the taint character and return it to the caller if (key.startsWith(TAINT_CHAR)) { return key.substring(1); } + String msg = getResourceString(key); + return (msg != null) ? msg : key; + } + + /** + * Get a String from the resource bundle, or null if there was an error. + */ + protected String getResourceString (String key) + { try { - return _bundle.getString(key); + if (_bundle != null) { + return _bundle.getString(key); + } } catch (MissingResourceException mre) { Log.warning("Missing translation message " + "[bundle=" + _path + ", key=" + key + "]."); - return key; } + return null; } /** @@ -117,21 +122,9 @@ public class MessageBundle */ public String get (String key, Object[] args) { - // if we were unable to resolve our resource bundle, we can't do - // any translations - if (_bundle == null) { - return key + StringUtil.toString(args); - } - - try { - String message = _bundle.getString(key); - return MessageFormat.format(message, args); - - } catch (MissingResourceException mre) { - Log.warning("Missing translation message " + - "[bundle=" + _path + ", key=" + key + "]."); - return key + StringUtil.toString(args); - } + String msg = getResourceString(key); + return (msg != null) ? MessageFormat.format(msg, args) + : (key + StringUtil.toString(args)); } /**