22

我正在尝试使用属性文件国际化 UIBinder 应用程序。由于我们已经通过 com.google.gwt.i18n.client.Messages 接口(GWT 1.7.1)公开了很多翻译,我们希望重用这些消息。

我尝试了以下方法:

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
 xmlns:g="urn:import:com.google.gwt.user.client.ui" 
 xmlns:res="ui:with:be.credoc.iov.webapp.client.MessageConstants">

 <g:HTMLPanel>
  <div>
   <res:msg key="email">Emaileke</res:msg>:
   <g:TextBox ui:field="email" />
  </div>
 </g:HTMLPanel>
</ui:UiBinder>

MessageConstants 类如下所示:

@DefaultLocale("nl")
public interface MessageConstants extends Messages {
 String email();
}

但是,这不起作用。我怎样才能做到这一点?

4

3 回答 3

29

更新:

自从伊戈尔写下他的答案以来,就有了一种在 ui binder 中使用消息的新方法。

<span>This <ui:text from="{msgRes.message}" /> has been internationalized</span>

此方法使用 GWT 的文本资源 UiBinder 集成

于 2011-08-30T04:15:20.763 回答
13

更新:
请在下面查看logan 的答案以获取最新版本的 GWT 中可用的解决方案。


我有(实际上,有)和你一样的问题——在迁移到 GWT 2.0 之后,我有一个我想在我的 UiBinder 文件中使用的属性文件。不幸的是,我无法让它像我想要的那样工作 - 似乎 GWT 开发人员希望人们使用UiBinder 的 i18n 指南中描述的语法- 在编译期间为每个 UiBinder 模板等创建一个消息接口。

无论如何,您仍然可以使用Messages这样的外部接口:

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
    xmlns:g="urn:import:com.google.gwt.user.client.ui">
    <ui:with field='cc' type='path.to.i18n.SomeMessages'/>
    <ui:with field='res' type='path.to.resource.ResourceBundle'/>
    <ui:style>
        .required {
      color: red;
      font-weight: bold;
    }
    .right {
      text-align: right;    
    }
    .textBox {
      margin-right: 7px;
    }
    </ui:style>
    <g:HTMLPanel styleName='{res.style.form} {res.style.mbox}' ui:field='mainPanel'>
        <h2 ui:field='loginHeader' />
      <h3 ui:field='loginLabel' />
      <div class='{style.textBox}'><g:TextBox ui:field="loginBox" /></div>
      <h3 ui:field='passwordLabel' />
    <div class='{style.textBox}'><g:PasswordTextBox ui:field="passwordBox" /></div>
    <div><g:CheckBox ui:field='rememberMeCheckBox' text='{cc.rememberMeCheckboxText}' /></div>
    <div class='{style.right}'><g:Button ui:field='submitButton' text='{cc.loginSubmitButtonText}' /></div>
    </g:HTMLPanel>
</ui:UiBinder> 

虽然,这仅适用于诸如Button标题等内容,而不适用于 div 的内容:/ 您可以在 UiBinder 模板后面的类中填写这些内容,但应该有更好的方法。

我希望您可以通过设置内部 HTML innerHTML(因为 UiBinder 应该识别该方法并允许通过 XML/UiBinder 模板设置它的值)但是唉,上次我检查它不起作用:/

于 2010-02-18T11:27:48.733 回答
8

UiBinder 与国际化相结合存在一个已知问题,另请参阅 gwt bugtracker 上的此最新主题:http ://code.google.com/p/google-web-toolkit/issues/detail?id=4355 。

评论 4中给出了一个解决方案:

如果您的 UiBinder 文件被称为“LoginView.ui.xml”,则调用属性文件 LoginViewLoginViewUiBinderImplGenMessages.properties(是的,“LoginView”出现两次)并将其放在源包中视图的 java 文件旁边,因此您完全可以将有 3 个文件:

LoginView.ui.xml
LoginView.java
LoginViewLoginViewUiBinderImplGenMessages.properties
于 2010-02-18T11:25:49.457 回答