【问题标题】:Alternative to uibinder I18nuibinder I18n 的替代品
【发布时间】:2012-07-26 12:37:29
【问题描述】:

here 所述,有 Uibinder 执行 i18n 的方法
然后是this GWT i18n 的建议。

我正在考虑替代方案,因为我在第一个解决方案中遇到了一些问题。 我想知道这两种方法的优缺点,所以我知道该选择什么。
请指教。

【问题讨论】:

    标签: gwt localization internationalization uibinder


    【解决方案1】:

    第一个解决方案非常冗长,需要您将本地化文件放在特定文件夹中,并被描述为a kind of a nightmare,但它确实支持带有(运行时)变量的文本。第二种解决方案不支持消息中的变量,但更易于使用。

    第二种解决方案支持 2 个用例。这就是他们寻找两种解决方案的方式:

    纯文本:

    解决方案 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>
    

    解决方案 2:

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

    在解决方案 1 中,标签内的文本将是默认文本,描述位于 description 属性中。在第二个解决方案中,您将在扩展 Messages 的接口类 MyMessages 中添加它。

    静态方法参数:

    解决方案 1:

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

    解决方案 2:

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

    解决方案 2 无法对消息进行任何更高级的使用,例如传递参数,但您始终可以在 initWidget 调用之后将它们添加到构造函数中。

    【讨论】:

    • UiBinder I18N 当你的消息中有小部件时真的很出色,例如&lt;ui:msg&gt;As a &lt;g:TextBox ui:field="userType" /&gt;, I want to &lt;g:TextBox ui:field="goal" /&gt;, so that &lt;g:TextBox ui:field="reason" /&gt;.。有了ui:baseMessagesInterface,它就不再是一场噩梦了,几乎可以与所谓的“解决方案 2”相提并论。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多