On Thu, Jul 28, 2016 at 11:19 AM, Vojtech Szocs <vszocs@redhat.com> wrote:Hi Ramesh,
this issue seems to be related with removal of @DefaultMessage annotations,
moving the default (English) strings into corresponding .properties files.Apparently if both properties file definitions and annotations are connected to the same message method, the properties version takes precidence. I wasn't sure if this applied to alternate messages, but your problem clearly shows that it does.As we generally want default strings to reside in .properties files, I see
following options to explore, based on our earlier conversation:
1, try annotating UIMessages interface with:
@Generate(format = "com.google.gwt.i18n.server.PropertyCatalogFactory")
- ref: https://github.com/gwtproject/gwt/issues/7032#issuecomment-110858030
- this is likely non-feasible, however, since @Generate requests generation
of translation sources (.properties) from Java code
2, try removing @AlternateMessage annotation and modify .properties file:
recurrenceType=Incorrect enum
recurrenceType[UNKNOWN]=None
recurrenceType[INTERVAL]=Minute
recurrenceType[HOURLY]=Hourly
recurrenceType[DAILY]=Daily
recurrenceType[WEEKLY]=Weekly
recurrenceType[MONTHLY]=Monthly
- ref: http://www.gwtproject.org/doc/latest/DevGuideI18nPluralForms.html
- this might not work as it might be @PluralCount-only (not for @Select)
I just tried this alternate messages in properties file technique and it will work.UIMessages.java:String recurrenceType(@Messages.Select GlusterVolumeSnapshotScheduleRecurrence recurrence);UIMessage.properties:recurrenceType=Incorrect enum
recurrenceType[UNKNOWN]=None
recurrenceType[INTERVAL]=Minute
recurrenceType[HOURLY]=Hourly
recurrenceType[DAILY]=Daily
recurrenceType[WEEKLY]=Weekly
recurrenceType[MONTHLY]=Monthly
The generated code looks like this:public java.lang.String recurrenceType(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotScheduleRecurrence arg0) {
java.lang.String returnVal = null;
int arg0_ordinal = -1;
if (arg0 != null) {
arg0_ordinal = arg0.ordinal();
}
switch (arg0_ordinal) {
case 2: // DAILY
returnVal = "Daily";
break;
case 1: // HOURLY
returnVal = "Hourly";
break;
case 0: // INTERVAL
returnVal = "Minute";
break;
case 4: // MONTHLY
returnVal = "Monthly";
break;
case 5: // UNKNOWN
returnVal = "None";
break;
case 3: // WEEKLY
returnVal = "Weekly";
break;
}
if (returnVal != null) {
return returnVal;
}
return "Incorrect enum";
}
3, remove @AlternateMessage & handle enum-to-string formatting on our own
String sizeUnitString(String size, @Messages.Select SizeConverter.SizeUnit sizeUnit);
becomes
String sizeUnitString(String size, String sizeUnitValue);
String recurrenceType(@Select GlusterVolumeSnapshotScheduleRecurrence recurrence);
gets removed, because there is no point in having "{0}" message
getMessages().sizeUnitString(size, sizeUnit);
becomes
getMessages().sizeUnitString(size, <someUtility>(sizeUnit));
getMessages().recurrenceType(recurrence);
becomes
<someUtility>(recurrence);
Personally, I think 3, is the most correct solution. As Alex wrote below,
we're planning to switch away from GWT i18n mechanism in the long-term;
relying on @AlternateMessage etc. is therefore an obstacle to that effort.
Option 2 is the most expedient and least intrusive. As a bonus, those alternate strings will be pushed out to the translators without having to do additional work/changes.
Also, we already have infra for localizing enum members: LocalizedEnums
So as part of solution 3, we should add into LocalizedEnums:
String GlusterVolumeSnapshotScheduleRecurrence___INTERVAL();
String GlusterVolumeSnapshotScheduleRecurrence___HOURLY();
String GlusterVolumeSnapshotScheduleRecurrence___DAILY();
String GlusterVolumeSnapshotScheduleRecurrence___WEEKLY();
String GlusterVolumeSnapshotScheduleRecurrence___MONTHLY();
String GlusterVolumeSnapshotScheduleRecurrence___UNKNOWN();
plus add corresponding strings in LocalizedEnums.properties file.
This way, we can leverage existing EnumTranslator#translate method.
By doing so, <someUtility> mentioned above === EnumTranslator#translate
Regards,
Vojtech
----- Original Message -----
> From: "Alexander Wels" <awels@redhat.com>
> To: "Ramesh Nachimuthu" <rnachimu@redhat.com>
> Cc: "devel" <devel@ovirt.org>, "Vojtech Szocs" <vszocs@redhat.com>, "Scott Dickerson" <sdickers@redhat.com>
> Sent: Thursday, July 28, 2016 2:21:23 PM
> Subject: Re: Strange issues with com.google.gwt.i18n.client.Messages.AlternateMessage [bz#1358837]
>
> On Thursday, July 28, 2016 05:49:57 AM Ramesh Nachimuthu wrote:
> > Hi,
> >
> > We have a strange issue with the
> > com.google.gwt.i18n.client.Messages.AlternateMessage in UIMessages.java. We
> > have defined some alternate messages using @Messages.Select with Enums. But
> > its doesn't work any more.
> >
> > We have following messages in the UIMessages.java.
> >
> > @Messages.AlternateMessage(value = { "UNKNOWN" , "None" , "INTERVAL" ,
> > "Minute" , "HOURLY" , "Hourly" , "DAILY" , "Daily" , "WEEKLY" , "Weekly" ,
> > "MONTHLY" , "Monthly" }) String recurrenceType(@Messages.Select
> > GlusterVolumeSnapshotScheduleRecurrence recurrence);
> >
> > @Messages.AlternateMessage(value = { "BYTES" , "{0} B" , "KiB" , "{0}
> > KiB" , "MiB" , "{0} MiB" , "GiB" , "{0} GiB" , "TiB" , "{0} TiB" }) String
> > sizeUnitString(String size, @Messages.Select
> > SizeConverter.SizeUnit sizeUnit);
> >
> > But the generated UIMessages_.java doesn't use any of the enum conditions.
> >
> > public java.lang.String
> > recurrenceType(org.ovirt.engine.core.common.businessentities.gluster.Gluste
> > rVolumeSnapshotScheduleRecurrence arg0) { java.lang.String returnVal =
> > null;
> > int arg0_ordinal = -1;
> > if (arg0 != null) {
> > arg0_ordinal = arg0.ordinal();
> > }
> > if (returnVal != null) {
> > return returnVal;
> > }
> > return "Incorrect enum";
> > }
> >
> > public java.lang.String sizeUnitString(java.lang.String
> > arg0,org.ovirt.engine.core.common.utils.SizeConverter.SizeUnit arg1) {
> > java.lang.String returnVal = null;
> > int arg1_ordinal = -1;
> > if (arg1 != null) {
> > arg1_ordinal = arg1.ordinal();
> > }
> > if (returnVal != null) {
> > return returnVal;
> > }
> > return arg0 + " TiB";
> > }
> >
> > It used to work earlier. Is there any known issue in the current GWT
> > Version? or Am I missing something?.
> >
> > Regards,
> > Ramesh
>
> We have an active project to remove all the annotations from the Messages
> interfaces in the project. I am guessing that is probably the cause of your
> problems. I am fairly certain there is an alternative to the annotations now,
> but I don't know of the top of my head. Scott can you give them the details?
>
> Alexander
>
>
Regards,Scott
--RHEV-M Engineering - UX TeamScott DickersonSenior Software Engineer
Red Hat, Inc
_______________________________________________
Devel mailing list
Devel@ovirt.org
http://lists.ovirt.org/mailman/listinfo/devel