【问题标题】:GWT dynamic string i18n with uibinder带有 uibinder 的 GWT 动态字符串 i18n
【发布时间】:2012-01-11 09:15:07
【问题描述】:

我正在尝试使用动态字符串 i18n 将使用 GWT UI Binder 运行的应用程序国际化。 UI binder 是否支持动态字符串 i18n?请告诉我这是否可能。

【问题讨论】:

    标签: java gwt internationalization


    【解决方案1】:

    UiBinder 模板可以标记为本地化。您使用 <ui:msg><ui:attribute> 元素来指示 模板应该被翻译,然后提供属性文件 构建应用程序时消息的本地化版本。 More关于它

    更新: 看到这个GWT Dynamic String Internationalization,我想你可以从那里找到解决方案。

    【讨论】:

    • 感谢您的回复。但我想知道 DYNAMIC i18n 是否可行。我知道静态字符串 i18n 可以使用 uibinder
    • 该链接阐明了静态 i18n。您可以从消息界面中看到。它不是动态的
    【解决方案2】:

    回答您的问题 - 是的,UI Binder 支持 i18n。请参阅可用的文档 herehere。为了支持我的主张,这里是直接引用:

    UiBinder... 直接支持与 GWT 的 i18n 工具配合使用的国际化;

    您只需创建一些具有指定语言环境的 *.properties 文件,在 gwt-xml 中启用 i18n 模块,创建一个接口,该接口可以在 Java 代码和 ui-xml 文件中访问方法(返回字符串)。

    【讨论】:

    • 感谢您的回复。但我想知道 DYNAMIC i18n 是否可行。我知道静态字符串 i18n 可以使用 uibinder
    【解决方案3】:

    我们已经使用 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>
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多