Search code examples
gwtlocalizationinternationalizationuibinder

Alternative to uibinder I18n


There is the Uibinder way of doing i18n as described here
And then there is this suggestion for GWT i18n.

I am considering the alternative as I am experiencing some issues with the first solution. I wish to know the pros and cons of both methods so I know what to choose.
Please advise.


Solution

  • The first solution is very verbose, requires you to put localization files in specific folders and is described as a kind of a nightmare but it does support text with (runtime) variables. The second solution doesn't support variables in messages, but is much easier to use.

    The second solution support 2 use cases. This is how they look for both solutions:

    Plain text:

    Solution 1:

    <ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
        ui:generateFormat='com.google.gwt.i18n.rebind.format.PropertiesFormat'
        ui:generateKeys="com.google.gwt.i18n.rebind.keygen.MD5KeyGenerator"
        ui:generateLocales="default">
      <div><ui:msg key="helloWorld" description="Greeting">Hello, world.</ui:msg></div>
    </ui:UiBinder>
    

    Solution 2:

    <ui:with field='i18n' type='x.y.client.i18n.MyMessages' />
    ....
    <div><ui:text from="{i18n.helloWorld}" /></div>
    

    In the solution 1 the text inside the tag will be the default text and the description is in the description attribute. In the second solution you would add that in the interface class MyMessages which extends Messages.

    Static method argument:

    Solution 1:

    <th title="Gross receipts">
      <ui:attribute ui:name='title' ui:description='Tooltip text for gross column'/>
      ...
    </th>
    

    Solution 2:

    <th title="{i18n.grossReceiptsTitle}">...</th>
    

    Any more advanced usage of message like passing arguments is not possible with solution 2, but you can always fall back to add them in your constructor after the initWidget call.