Summary: | fmt strips quotes when using parameter | ||
---|---|---|---|
Product: | Taglibs | Reporter: | Gael Marziou <gael.marziou> |
Component: | Standard Taglib | Assignee: | Tomcat Developers Mailing List <dev> |
Status: | RESOLVED INVALID | ||
Severity: | normal | ||
Priority: | P3 | ||
Version: | 1.0.5 | ||
Target Milestone: | --- | ||
Hardware: | Other | ||
OS: | other |
Description
Gael Marziou
2004-07-23 15:32:41 UTC
It may seem surprising, but it works as defined in the spec. What's happening is that the existence of a format parameter is causing the tag to use MessageFormat to process the message. Check out sections 8.8 <fmt:message> and 8.9 <fmt:param> of the spec, as well as the JavaDoc for java.text.MessageFormat. Here's some test code to illustrate the effect: import java.text.*; import java.util.*; public class FmtTest { public static class Messages extends ListResourceBundle { private static final Object[][] CONTENTS = { {"feedback2", "Rock'n Roll"}, {"feedback2-xtra-quote", "Rock''n Roll"} }; protected Object[][] getContents() { return CONTENTS; } } public static void main(String[] args) { ResourceBundle bundle = ResourceBundle.getBundle("FmtTest$Messages"); String feedback2 = bundle.getString("feedback2"); String feedback2XtraQuote = bundle.getString("feedback2-xtra-quote"); System.out.println("feedback2:"); System.out.println(feedback2); System.out.println(MessageFormat.format(feedback2, null)); System.out.println(); System.out.println("feedback2-xtra-quote:"); System.out.println(feedback2XtraQuote); System.out.println(MessageFormat.format(feedback2XtraQuote, null)); } } This will output: feedback2: Rock'n Roll Rockn Roll feedback2-xtra-quote: Rock''n Roll Rock'n Roll Thanks for your explanation, I think it should be a FAQ and it's too bad that the spec did go this way. It's a nightmare for localizers and for developers because the only suggestion in the MessageFormat javadoc is to use comments in resource bundle source files to indicate which strings will be processed by MessageFormat. What about evolutions? It's obvious that some parameters will be added during the life of an application and we should rely only on comments to avoid problems? Anyway, which better alternative do I have: - write my own tag to fix this "correct" behavior - always use <param> even if empty Any suggestion is welcome. |