The StringResourceModel uses MessageFormat patterns, so you could try
using a ChoiceFormat-based pattern. Try this out in a main method
somewhere to get an idea of what happens:
final String pattern = "{0,choice,0#none|1#one|2#couple|2<many}";
System.out.println(MessageFormat.format(pattern, 0));
System.out.println(MessageFormat.format(pattern, 1));
System.out.println(MessageFormat.format(pattern, 2));
System.out.println(MessageFormat.format(pattern, 100));
On Fri, Jun 13, 2008 at 9:22 AM, Kaspar Fischer <[EMAIL PROTECTED]> wrote:
> I frequently need to deal with singular and plural versions of
> wicket:message's.
> I would like to do something like:
>
> add(new Label("links", new PluralStringResourceModel("link", this)
> {
> @Override
> public boolean isPlural()
> {
> return /* some code like: */
> model.getObject().getChildren().size() > 1;
> }
> }));
>
> and this will use "link.plural" if isPlural() returns true and "link"
> otherwise.
>
> Has anybody found an elegant solution for such situations?
>
> P.S. Here is a working implementation (neither efficient nor elegant) for
> the above approach:
>
> add(new Label("link", new StringResourceModel("link${plural}",
> this, new Model<Serializable>()
> {
> @Override
> public Serializable getObject()
> {
> return new Serializable()
> {
> public String getPlural()
> {
> return model.getObject().getChildren().size() > 1 ? ".plural"
> : "";
> }
> };
> }
> })));
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]