PDA

View Full Version : Support for ChoiceFormat?



jeje
Oct 5th, 2004, 06:44 AM
Hi,

I am trying to figure out what is the best way to use a ChoiceFormat from Spring.

It seems that all the i18n support is based on a MessageFormat that can't be "parameterized" (the one returned from the createMessageFormat() method of the AbstractMessageSource class).

This means that if I need to use a ChoiceFormat, I do have to write a subclass of AbstractMessageSource, but then loose the "flexibility" of the ResourceBundleMessageSource and the reloadable equivalent. Wouldn't it be nicer if the "strategy" of message formats was somehow externalized from the AbstractMessageSource?

Any idea on how to elegantly solve this issue?

jeje
Oct 5th, 2004, 10:29 AM
After digging intensively in the JDK doco, I found the following way of using a choice format:

pattern=There {0,choice,0#are no files|1#is one file|1<are {2} files} on {1}

Quite tricky, but hey it works :-)