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
This commit is contained in:
@@ -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 <code>{</code> and
|
||||
* <code>}</code> 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;
|
||||
|
||||
Reference in New Issue
Block a user