You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by Olivier Croisier <ol...@gmail.com> on 2009/11/11 18:47:41 UTC

Patch for easy Enums I18N

Hi,

I just submitted a patch to the very old
WICKET-1157<https://issues.apache.org/jira/browse/WICKET-1157>JIRA (no
activity for the last 2 years).
It provides a simple and flexible way to internationalize enums :
- An EnumMessageKeyProvided that implements a Strategy pattern to generate
I18N keys from enums.
- An EnumDropDownChoice to render HTML <select> components
- An EnumModel to internationalize any enum provided by another Model (so
there is no need of EnumLabels and such).

Hope that helps,

Olivier

Re: Patch for easy Enums I18N

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
Component is optional so it can be given optionally to the renderer.

I have attached a patch. However, it should still be coupled with
TypeChoiceModel so that they fetch the localized label using the same
method. I uploaded that too.

I also provided factory methods so that it is easier to construct these objects.

**
Martin

2009/11/12 Olivier Croisier <ol...@gmail.com>:
> The Localizer methods also require a Component as a parameter, so we're back
> to square one : we must provide a Component.
> Also, it would be helpful if you provided your alternative implementation as
> a well-formed patch instead of plain-text code in the Jira comment.
>
>
> On Wed, Nov 11, 2009 at 8:44 PM, Martin Makundi <
> martin.makundi@koodaripalvelut.com> wrote:
>
>> > I admit the EnumDropDownChoice is more of a convenient class that a
>> > real new feature.
>>
>> It's simply an overkill for the purpose. I loved the idea of a
>> TypeChoiceModel, though. Maybe it should also be tuned to be non
>> enum-specific, like the TypeChoiceRenderer.
>>
>> > A standalone EnumChoiceRenderer would need to take a Component as a
>> > constructor parameter, to call getString() on,
>>
>> This is not true. Localizer is available everywhere.
>>
>> Application.get().getResourceSettings().getLocalizer();
>>
>>
>> **
>> Martin
>> >
>> >
>> >
>> >
>> > On Wed, Nov 11, 2009 at 7:58 PM, Martin Makundi <
>> > martin.makundi@koodaripalvelut.com> wrote:
>> >
>> >> I vote for EnumChoiceRender instead of full DropDownChoice.
>> >>
>> >> However. EnumChoiceRenderer can render any TYPE so that's why I have
>> >> proposed TypeChoiceRenderer. You can directly use it with existing
>> >> wicket and no need for specific dropdown.
>> >>
>> >> **
>> >> Martin
>> >>
>> >> 2009/11/11 Olivier Croisier <ol...@gmail.com>:
>> >> > Hi,
>> >> >
>> >> > I just submitted a patch to the very old
>> >> > WICKET-1157<https://issues.apache.org/jira/browse/WICKET-1157>JIRA
>> (no
>> >> > activity for the last 2 years).
>> >> > It provides a simple and flexible way to internationalize enums :
>> >> > - An EnumMessageKeyProvided that implements a Strategy pattern to
>> >> generate
>> >> > I18N keys from enums.
>> >> > - An EnumDropDownChoice to render HTML <select> components
>> >> > - An EnumModel to internationalize any enum provided by another Model
>> (so
>> >> > there is no need of EnumLabels and such).
>> >> >
>> >> > Hope that helps,
>> >> >
>> >> > Olivier
>> >> >
>> >>
>> >
>>
>

Re: Patch for easy Enums I18N

Posted by Olivier Croisier <ol...@gmail.com>.
The Localizer methods also require a Component as a parameter, so we're back
to square one : we must provide a Component.
Also, it would be helpful if you provided your alternative implementation as
a well-formed patch instead of plain-text code in the Jira comment.


On Wed, Nov 11, 2009 at 8:44 PM, Martin Makundi <
martin.makundi@koodaripalvelut.com> wrote:

> > I admit the EnumDropDownChoice is more of a convenient class that a
> > real new feature.
>
> It's simply an overkill for the purpose. I loved the idea of a
> TypeChoiceModel, though. Maybe it should also be tuned to be non
> enum-specific, like the TypeChoiceRenderer.
>
> > A standalone EnumChoiceRenderer would need to take a Component as a
> > constructor parameter, to call getString() on,
>
> This is not true. Localizer is available everywhere.
>
> Application.get().getResourceSettings().getLocalizer();
>
>
> **
> Martin
> >
> >
> >
> >
> > On Wed, Nov 11, 2009 at 7:58 PM, Martin Makundi <
> > martin.makundi@koodaripalvelut.com> wrote:
> >
> >> I vote for EnumChoiceRender instead of full DropDownChoice.
> >>
> >> However. EnumChoiceRenderer can render any TYPE so that's why I have
> >> proposed TypeChoiceRenderer. You can directly use it with existing
> >> wicket and no need for specific dropdown.
> >>
> >> **
> >> Martin
> >>
> >> 2009/11/11 Olivier Croisier <ol...@gmail.com>:
> >> > Hi,
> >> >
> >> > I just submitted a patch to the very old
> >> > WICKET-1157<https://issues.apache.org/jira/browse/WICKET-1157>JIRA
> (no
> >> > activity for the last 2 years).
> >> > It provides a simple and flexible way to internationalize enums :
> >> > - An EnumMessageKeyProvided that implements a Strategy pattern to
> >> generate
> >> > I18N keys from enums.
> >> > - An EnumDropDownChoice to render HTML <select> components
> >> > - An EnumModel to internationalize any enum provided by another Model
> (so
> >> > there is no need of EnumLabels and such).
> >> >
> >> > Hope that helps,
> >> >
> >> > Olivier
> >> >
> >>
> >
>

Re: Patch for easy Enums I18N

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
> I admit the EnumDropDownChoice is more of a convenient class that a
> real new feature.

It's simply an overkill for the purpose. I loved the idea of a
TypeChoiceModel, though. Maybe it should also be tuned to be non
enum-specific, like the TypeChoiceRenderer.

> A standalone EnumChoiceRenderer would need to take a Component as a
> constructor parameter, to call getString() on,

This is not true. Localizer is available everywhere.

Application.get().getResourceSettings().getLocalizer();


**
Martin
>
>
>
>
> On Wed, Nov 11, 2009 at 7:58 PM, Martin Makundi <
> martin.makundi@koodaripalvelut.com> wrote:
>
>> I vote for EnumChoiceRender instead of full DropDownChoice.
>>
>> However. EnumChoiceRenderer can render any TYPE so that's why I have
>> proposed TypeChoiceRenderer. You can directly use it with existing
>> wicket and no need for specific dropdown.
>>
>> **
>> Martin
>>
>> 2009/11/11 Olivier Croisier <ol...@gmail.com>:
>> > Hi,
>> >
>> > I just submitted a patch to the very old
>> > WICKET-1157<https://issues.apache.org/jira/browse/WICKET-1157>JIRA (no
>> > activity for the last 2 years).
>> > It provides a simple and flexible way to internationalize enums :
>> > - An EnumMessageKeyProvided that implements a Strategy pattern to
>> generate
>> > I18N keys from enums.
>> > - An EnumDropDownChoice to render HTML <select> components
>> > - An EnumModel to internationalize any enum provided by another Model (so
>> > there is no need of EnumLabels and such).
>> >
>> > Hope that helps,
>> >
>> > Olivier
>> >
>>
>

Re: Patch for easy Enums I18N

Posted by Olivier Croisier <ol...@gmail.com>.
Hi,

Thanks for your answer.

I admit the EnumDropDownChoice is more of a convenient class that a real new
feature.
However, it has the benefit of providing its enclosed EnumChoiceRenderer a
base component to call getString() on. A standalone EnumChoiceRenderer would
need to take a Component as a constructor parameter, to call getString() on,
and I thought it might be a bit confusing for the developers.
Now, if everyone finds it better, I am willing to submit a new patch with
only the EnumChoiceRenderer, modified as required.

On the other hand, any remarks on the EnumMessageKeyProvider system ?

Olivier




On Wed, Nov 11, 2009 at 7:58 PM, Martin Makundi <
martin.makundi@koodaripalvelut.com> wrote:

> I vote for EnumChoiceRender instead of full DropDownChoice.
>
> However. EnumChoiceRenderer can render any TYPE so that's why I have
> proposed TypeChoiceRenderer. You can directly use it with existing
> wicket and no need for specific dropdown.
>
> **
> Martin
>
> 2009/11/11 Olivier Croisier <ol...@gmail.com>:
> > Hi,
> >
> > I just submitted a patch to the very old
> > WICKET-1157<https://issues.apache.org/jira/browse/WICKET-1157>JIRA (no
> > activity for the last 2 years).
> > It provides a simple and flexible way to internationalize enums :
> > - An EnumMessageKeyProvided that implements a Strategy pattern to
> generate
> > I18N keys from enums.
> > - An EnumDropDownChoice to render HTML <select> components
> > - An EnumModel to internationalize any enum provided by another Model (so
> > there is no need of EnumLabels and such).
> >
> > Hope that helps,
> >
> > Olivier
> >
>

Re: Patch for easy Enums I18N

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
I vote for EnumChoiceRender instead of full DropDownChoice.

However. EnumChoiceRenderer can render any TYPE so that's why I have
proposed TypeChoiceRenderer. You can directly use it with existing
wicket and no need for specific dropdown.

**
Martin

2009/11/11 Olivier Croisier <ol...@gmail.com>:
> Hi,
>
> I just submitted a patch to the very old
> WICKET-1157<https://issues.apache.org/jira/browse/WICKET-1157>JIRA (no
> activity for the last 2 years).
> It provides a simple and flexible way to internationalize enums :
> - An EnumMessageKeyProvided that implements a Strategy pattern to generate
> I18N keys from enums.
> - An EnumDropDownChoice to render HTML <select> components
> - An EnumModel to internationalize any enum provided by another Model (so
> there is no need of EnumLabels and such).
>
> Hope that helps,
>
> Olivier
>