Search code examples
gwtlocalizationuibinder

how to localize DateLabel and NumberLabel customFormat attribute?


I am in the process of localizing a rather large GWT UIbinder code base and ran across a couple of instances where the process of setting attributes does not work.

DateLabel javadoc

NumberLabel javadoc

I need to specify the date format and number format in a LocalizableResource_xx.properties file for DateLabel and NumberLabel widgets.

I tried converting this fragment

   <g:DateLabel styleName="{style.formPromptData}" 
        ui:field="createDate" customFormat="MMM d, yyyy" /> 

using the ui:attribute method with no success

Invoking generator com.google.gwt.uibinder.rebind.UiBinderGenerator [ERROR] No method found to apply message attribute customFormat Element (:63)

Is there a way to localize these elements?


Solution

  • customFormat="XXX" translates to DateTimeFormat.getFormat("XXX") and is no different wrt localization: that is, it's not localizable.

    If you want a localizable custom format, use a CustomDateTimeFormat (that currently relies on ICU4J's DateTimePatternGenerator) or a Constants or Messages interface. Instantiate it with <ui:with> and use with customFormat="{intf.customPattern}" (format="{intf.customPattern}" actually if you use a CustomDateTimeFormat).