diff --git a/src/as/com/threerings/util/MessageBundle.as b/src/as/com/threerings/util/MessageBundle.as index a6acfc917..5ef904483 100644 --- a/src/as/com/threerings/util/MessageBundle.as +++ b/src/as/com/threerings/util/MessageBundle.as @@ -190,22 +190,14 @@ public class MessageBundle } // look up our message string, selecting the proper plurality - // string if our first argument is an Integer + // string if our first argument can be coaxed into an integer var msg :String = getResourceString(key + getSuffix(args), false); - // if the base key is not found, look to see if we should try to - // convert our first argument to an Integer and try again + // if the suffixed key was not found, just try the original key if (msg == null) { - if (getResourceString(key + ".n", false) != null) { - // try converting the first arg to an int - try { - args[0] = StringUtil.parseInteger(args[0]); - msg = getResourceString(key + getSuffix(args), false); - } catch (err :Error) { - // fall through... - } - } - // if the msg is still null, we have a problem + msg = getResourceString(key, false); + + // if the msg is still missing, we have a problem if (msg == null) { Log.getLog(this).warning("Missing translation message " + "[bundle=" + _path + ", key=" + key + "]."); @@ -221,15 +213,17 @@ public class MessageBundle /** * A helper function for {@link #get(String,Object[])} that allows us * to automatically perform plurality processing if our first argument - * is an {@link Integer}. + * can be coaxed to an {@link Integer}. */ protected function getSuffix (args :Array) :String { - if (args.length > 0 && args[0] is int) { + if (args.length > 0) { + var count :int = int(args[0]); switch (args[0]) { - case 0: return ".0"; - case 1: return ".1"; - default: return ".n"; + case NaN: break; // Fall out + case 0: return ".0"; + case 1: return ".1"; + default: return ".n"; } } return ""; diff --git a/src/java/com/threerings/util/MessageBundle.java b/src/java/com/threerings/util/MessageBundle.java index 87678913f..ca056f490 100644 --- a/src/java/com/threerings/util/MessageBundle.java +++ b/src/java/com/threerings/util/MessageBundle.java @@ -300,30 +300,18 @@ public class MessageBundle // if the base key is not found, look to see if we should try to // convert our first argument to an Integer and try again if (msg == null) { - if (getResourceString(key + ".n", false) != null) { - try { - // args could be a String[], we need to turn it into - // an Object[] - Object[] newargs = new Object[args.length]; - System.arraycopy(args, 1, newargs, 1, args.length - 1); - newargs[0] = new Integer(args[0].toString()); - args = newargs; - msg = getResourceString(key + getSuffix(args)); - } catch (Exception e) { - log.warning("Failure doing automatic plural handling " + - "[bundle=" + _path + ", key=" + key + - ", args=" + StringUtil.toString(args) + - ", error=" + e + "]."); - } + msg = getResourceString(key, false); - } else { + if (msg == null) { log.warning("Missing translation message", "bundle", _path, "key", key, new Exception()); + + // return something bogus + return (key + StringUtil.toString(args)); } } - return (msg != null) ? MessageFormat.format(MessageUtil.escape(msg), args) : - (key + StringUtil.toString(args)); + return MessageFormat.format(MessageUtil.escape(msg), args); } /** @@ -338,15 +326,21 @@ public class MessageBundle /** * A helper function for {@link #get(String,Object[])} that allows us * to automatically perform plurality processing if our first argument - * is an {@link Integer}. + * can be coaxed to an {@link Integer}. */ protected String getSuffix (Object[] args) { - if (args[0] instanceof Integer) { - switch (((Integer)args[0]).intValue()) { - case 0: return ".0"; - case 1: return ".1"; - default: return ".n"; + if (args.length > 0) { + try { + int count = (args[0] instanceof Integer) ? (Integer)args[0] : + Integer.parseInt(args[0].toString()); + switch (count) { + case 0: return ".0"; + case 1: return ".1"; + default: return ".n"; + } + } catch (NumberFormatException e) { + // Fall out } } return "";