i18nCreator Generate Messages Interface With Argument Type Other Than String
I was trying to learn GWT. I completed the StockWatcher sample app in the tutorial.
I then moved onto the next st开发者_如何学编程ep: Internationalization (I18N).
The I18N tutorial has you create the Message and Constant interfaces manually. One of the Message files looks like this:
public interface StockWatcherMessages extends Messages {
@DefaultMessage("''{0}'' is not a valid symbol.")
String invalidSymbol(String symbol);
@DefaultMessage("Last update: {0,date,medium} {0,time,medium}")
String lastUpdate(Date timestamp);
}
Notice the Date
type parameter in one of the methods. This allows me to pass in a Date
instance when I call this method and it gets displayed ina localized fashion. This worked just fine.
GWT also has a tool called i18nCreator which can be used to Generate these interfaces for you, based on the corresponding .properties
files.
I am using the gwt-maven-plugin to build my app and it also supports using the i18nCreator as an automatic part of your build.
So my problem is that when I use the i18nCreator, either explicitly or through the maven plugin, I end up with a Message interface like this:
public interface StockWatcherMessages extends com.google.gwt.i18n.client.Messages {
@DefaultMessage("''{0}'' is not a valid symbol.")
@Key("invalidSymbol")
String invalidSymbol(String arg0);
@DefaultMessage("Last update: {0,date,medium} {0,time,medium}")
@Key("lastUpdate")
String lastUpdate(String arg0);
}
The argument to lastUpdate
is now a String. This causes the rest of my code, which calls this method with a Date
instance, to fail compilation.
How can I make the i18nCreator create interfaces using Java types other than Strings when appropriate? I am having this problem with Date
but I imagine it could come up with other types like Money
or Double
or whatever.
精彩评论