GWT UiBinder I18n
GWT UiBinder I18n
正如标题所说,我需要一些有关 GWT 的 i18n 与 UiBinder 一起使用的帮助。我想使用静态 i18n 将我的应用程序国际化。我用来学习的书仅介绍了一种通过让编译器为 Constants/Messages 和默认文件生成密钥来使 ui.xml 文件国际化的方法,但是必须有一种更简单的方法来执行此操作。这就是为什么我尝试像这样使用 ui:with 标签来使用我的国际化常量(在 upFace 内部):
<ui:with type="havis.ui.shared.resourcebundle.ConstantsResource" field="lang"></ui:with>
<g:ToggleButton ui:field="observeButton">
<g:upFace>{lang.observe}</g:upFace>
<g:downFace>Observing</g:downFace>
</g:ToggleButton>
这不起作用,按钮显示文本 {lang.observe} 这似乎也合乎逻辑,但现在我的问题是:有没有办法像这样使用常量?如果不能,有人可以解释我应该如何在 UiBinder 文件中使用常量(而不让编译器生成文件和密钥)吗?
您可以像这样使用常量:
.ui.xml :
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'>
<ui:with field="constants" type="my.client.resources.AppResources.AppConstants"/>
<g:FlowPanel>
<g:Label text="{constants.label}"/>
</g:FlowPanel>
和 AppResources 接口:
public interface ApplicationResources extends ClientBundle {
public static final ApplicationConstants CONSTANTS = GWT.create(ApplicationConstants.class);
public interface ApplicationConstants extends com.google.gwt.i18n.client.Constants {
@DefaultStringValue("my label")
String label();
}
}
但对于 i18n,您应该真正遵循 GWT 手册中的说明,即
除了准备所有 属性 文件(每种语言一个)并生成所有必需的排列外,没有其他(干净)的方法。这主要代表
给GWT所有语言检测相关的东西,以及提供的解决方案
GWT 在运行时表现相当好。唯一的缺点是编译时间
稍微高一点(因为您将针对您指定的每种语言的每种浏览器进行排列)。
接受 HTML 的任何地方(例如 upFace
内),您可以使用 <ui:msg>
、<ui:text>
和 <ui:safehtml>
(以及纯文本的任何地方)预期,您可以使用 <ui:msg>
和 <ui:text>
).
所以在你的情况下:
<ui:with type="havis.ui.shared.resourcebundle.ConstantsResource" field="lang"></ui:with>
<g:ToggleButton ui:field="observeButton">
<g:upFace><ui:text from="{lang.observe}"/></g:upFace>
<g:downFace>Observing</g:downFace>
</g:ToggleButton>
参见 http://www.gwtproject.org/doc/latest/DevGuideUiBinder.html#Hello_Text_Resources and http://www.gwtproject.org/doc/latest/DevGuideUiBinder.html#Hello_Html_Resources 关于 ui:text
和 ui:safehtml
。
正如标题所说,我需要一些有关 GWT 的 i18n 与 UiBinder 一起使用的帮助。我想使用静态 i18n 将我的应用程序国际化。我用来学习的书仅介绍了一种通过让编译器为 Constants/Messages 和默认文件生成密钥来使 ui.xml 文件国际化的方法,但是必须有一种更简单的方法来执行此操作。这就是为什么我尝试像这样使用 ui:with 标签来使用我的国际化常量(在 upFace 内部):
<ui:with type="havis.ui.shared.resourcebundle.ConstantsResource" field="lang"></ui:with>
<g:ToggleButton ui:field="observeButton">
<g:upFace>{lang.observe}</g:upFace>
<g:downFace>Observing</g:downFace>
</g:ToggleButton>
这不起作用,按钮显示文本 {lang.observe} 这似乎也合乎逻辑,但现在我的问题是:有没有办法像这样使用常量?如果不能,有人可以解释我应该如何在 UiBinder 文件中使用常量(而不让编译器生成文件和密钥)吗?
您可以像这样使用常量:
.ui.xml :
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'>
<ui:with field="constants" type="my.client.resources.AppResources.AppConstants"/>
<g:FlowPanel>
<g:Label text="{constants.label}"/>
</g:FlowPanel>
和 AppResources 接口:
public interface ApplicationResources extends ClientBundle {
public static final ApplicationConstants CONSTANTS = GWT.create(ApplicationConstants.class);
public interface ApplicationConstants extends com.google.gwt.i18n.client.Constants {
@DefaultStringValue("my label")
String label();
}
}
但对于 i18n,您应该真正遵循 GWT 手册中的说明,即 除了准备所有 属性 文件(每种语言一个)并生成所有必需的排列外,没有其他(干净)的方法。这主要代表 给GWT所有语言检测相关的东西,以及提供的解决方案 GWT 在运行时表现相当好。唯一的缺点是编译时间 稍微高一点(因为您将针对您指定的每种语言的每种浏览器进行排列)。
接受 HTML 的任何地方(例如 upFace
内),您可以使用 <ui:msg>
、<ui:text>
和 <ui:safehtml>
(以及纯文本的任何地方)预期,您可以使用 <ui:msg>
和 <ui:text>
).
所以在你的情况下:
<ui:with type="havis.ui.shared.resourcebundle.ConstantsResource" field="lang"></ui:with>
<g:ToggleButton ui:field="observeButton">
<g:upFace><ui:text from="{lang.observe}"/></g:upFace>
<g:downFace>Observing</g:downFace>
</g:ToggleButton>
参见 http://www.gwtproject.org/doc/latest/DevGuideUiBinder.html#Hello_Text_Resources and http://www.gwtproject.org/doc/latest/DevGuideUiBinder.html#Hello_Html_Resources 关于 ui:text
和 ui:safehtml
。