我正在尝试使用属性文件来国际化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();
}
然而,这不起作用。我怎么能这样做?
答案 0 :(得分:28)
<强>更新强>
自从Igor写下他的答案以来,有一种在ui binder中使用消息的新方法。
<span>This <ui:text from="{msgRes.message}" /> has been internationalized</span>
此方法使用GWT的text resource UiBinder integration
答案 1 :(得分:13)
<强>更新强>
请查看下面的logan's answer以获取最新版GWT中可用的解决方案。
我(实际上,有)和你一样的问题 - 迁移到GWT 2.0之后我有一个我想在我的UiBinder文件中使用的属性文件。不幸的是,我无法像我想的那样工作 - 似乎GWT开发人员希望人们使用i18n guide for 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模板后面的类,但是应该是一个更好的方式。
我希望您可以通过innerHTML
设置内部HTML(因为UiBinder应该识别该方法并允许通过XML / UiBinder模板设置它的值)但是,上次我检查它时不起作用:/
答案 2 :(得分:8)
UiBinder与国际化相结合存在一个已知问题,另请参阅gwt bugtracker上的最新帖子:http://code.google.com/p/google-web-toolkit/issues/detail?id=4355。
在comment 4中给出了一个解决方案:
如果你的UiBinder文件被调用,比方说, 'LoginView.ui.xml'然后调用 属性文件LoginViewLoginViewUiBinderImplGenMessages.properties (是'LoginView'出现两次)并将其放在视图的java旁边 文件 在源包中,所以你总共有3个文件:
LoginView.ui.xml LoginView.java LoginViewLoginViewUiBinderImplGenMessages.properties