From 98e59b847eddc050367980c2dc4d64d3a31f41ce Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Wed, 5 Nov 2003 23:10:43 +0000 Subject: [PATCH] I discovered that ResourceBundle messages finally seem to do the right thing with unescaped ticks (') which led me to modify MessageBundle to automatically escape ticks before passing things to MessageFormat. This allows us to use unescaped ticks willy nilly in our translation strings. Yay! No more annoying worrying about whether we should use \' or '' or having things be booched because we forgot one or the other. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2850 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../com/threerings/util/MessageBundle.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/java/com/threerings/util/MessageBundle.java b/src/java/com/threerings/util/MessageBundle.java index 5ea68ab95..895b8a550 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.20 2003/05/20 20:58:31 mdb Exp $ +// $Id: MessageBundle.java,v 1.21 2003/11/05 23:10:43 mdb Exp $ package com.threerings.util; @@ -127,7 +127,7 @@ public class MessageBundle } Object[] args = new Object[] { new Integer(value) }; return (format == null) ? (key + StringUtil.toString(args)) : - MessageFormat.format(format, args); + MessageFormat.format(escape(format), args); } /** @@ -195,7 +195,7 @@ public class MessageBundle } String msg = getResourceString(key); - return (msg != null) ? MessageFormat.format(msg, args) + return (msg != null) ? MessageFormat.format(escape(msg), args) : (key + StringUtil.toString(args)); } @@ -451,6 +451,19 @@ public class MessageBundle return qualifiedKey.substring(qsidx+1); } + /** + * Used to escape single quotes so that they are not interpreted by + * {@link MessageFormat}. As we assume all single quotes are to be + * escaped, we cannot use the characters { and + * } in our translation strings, but this is a small + * price to pay to have to differentiate between messages that will + * and won't eventually be parsed by a {@link MessageFormat} instance. + */ + protected static String escape (String message) + { + return StringUtil.replace(message, "'", "''"); + } + /** The message manager via whom we'll resolve fully qualified * translation strings. */ protected MessageManager _msgmgr;