2015-05-18 220 views
0

正如标题所示,我需要GWT的i18n与UiBinder配合使用。我想用静态i18n国际化我的应用程序。我用于学习的书只介绍了一种通过让编译器为常量/消息和默认文件生成密钥来国际化ui.xml文件的方法,但必须有一种更简单的方法来执行此操作。这就是为什么我试图使用UI:像这样的标签来使用我的国际化常数(在upFace内):GWT UiBinder I18n

<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文件中使用常量(而不需要编译器生成文件和密钥)?

回答

2

Anywhere的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_Resourceshttp://www.gwtproject.org/doc/latest/DevGuideUiBinder.html#Hello_Html_Resourcesui:textui:safehtml

+0

谢谢,它工作正常! – Lunaetic

0

您可以使用常数是这样的:

.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(); 
    } 
} 

但对于国际化你真的应该遵循什么样的GWT手册说,即 是没有其他(干净)的方式比准备所有属性文件(每种语言一个)并生成所有需要的排列。这主要是将 委托给GWT所有与语言检测有关的东西,GWT提供的解决方案在运行时表现相当好。唯一的缺点是编译时间 稍微高一些(因为您将为每个指定的语言的每个浏览器进行排列)。

+0

我已经发现了这种方式,但我不太喜欢它/:但谢谢你试图帮助,我很欣赏它(: – Lunaetic