Jan*_*Jan 22 gwt internationalization uibinder
我试图用属性文件国际化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();
}
但是,这不起作用.我怎样才能做到这一点?
log*_*gan 28
更新:
自从Igor写下他的答案以来,有一种在ui binder中使用消息的新方法.
<span>This <ui:text from="{msgRes.message}" /> has been internationalized</span>
此方法使用GWT的文本资源UiBinder集成
Igo*_*mer 13
更新:
 
请查看下面的logan答案,了解最新版GWT中可用的解决方案.
我(实际上)有同样的问题 - 在迁移到GWT 2.0后,我有一个我想在我的UiBinder文件中使用的属性文件.不幸的是,我无法像我想的那样工作 - 似乎GWT开发人员希望人们使用i18n指南中为UiBinder描述的语法- 在编译期间为每个UiBinder模板创建一个Message接口,等等.
无论如何,你仍然可以使用这样的外部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模板设置它的值)但是,上次我检查它时不起作用:/
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个文件:
Run Code Online (Sandbox Code Playgroud)LoginView.ui.xml LoginView.java LoginViewLoginViewUiBinderImplGenMessages.properties