【发布时间】:2012-01-11 09:15:07
【问题描述】:
我正在尝试使用动态字符串 i18n 将使用 GWT UI Binder 运行的应用程序国际化。 UI binder 是否支持动态字符串 i18n?请告诉我这是否可能。
【问题讨论】:
标签: java gwt internationalization
我正在尝试使用动态字符串 i18n 将使用 GWT UI Binder 运行的应用程序国际化。 UI binder 是否支持动态字符串 i18n?请告诉我这是否可能。
【问题讨论】:
标签: java gwt internationalization
UiBinder 模板可以标记为本地化。您使用
<ui:msg>和<ui:attribute>元素来指示 模板应该被翻译,然后提供属性文件 构建应用程序时消息的本地化版本。 More关于它
更新: 看到这个GWT Dynamic String Internationalization,我想你可以从那里找到解决方案。
【讨论】:
我们已经使用 Dictionary 做到了这一点。基本上,您使用动态主机页面(例如 jsp)在主机页面中动态创建常量。要将它们与 UiBinder 一起使用,您几乎没有选择,但最直接的方法是围绕字典创建包装类,例如
package org.gwt.dictionary.test
public class CurrentTheme {
Dictionary theme = Dictionary.getDictionary("CurrentTheme");
public String highlightColor() {
return theme.get("highlightColor");
}
public String shadowColor() {
return theme.get("shadowColor");
}
public String errorColor() {
return theme.get("errorColor");
}
public String errorIconSrc() {
return theme.get("errorIconSrc");
}
public String errorLabel() {
return theme.get("errorLabel");
}
public String someTextContent() {
return theme.get("someTextContent");
}
}
然后你可以像这样在gwt.xml中使用它
<!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="themeConstants" type="org.gwt.dictionary.test.CurrentTheme"/>
<g:HTMLPanel>
<g:Label text="{themeConstants.errorLabel}" styleName="{themeConstants.errorColor}"/>
<div class="aler alert-info"><ui:text from="{themeConstants.someTextContent}"/></div>
</g:HTMLPanel>
</ui:UiBinder>
希望对你有帮助
【讨论】: