简体   繁体   English

GWT UiBinder I18n

[英]GWT UiBinder I18n

As the title says I need some help with GWT's i18n in use with UiBinder. 正如标题所述,我需要将GWT的i18n与UiBinder一起使用时需要一些帮助。 I want to internationalize my application using static i18n. 我想使用静态i18n国际化我的应用程序。 The book I use for learning only presents a way of internationalizing ui.xml files by having the compiler generate keys for Constants/Messages and a default file, but there has to be an easier way to do this. 我用来学习的书仅通过使编译器生成用于常量/消息和默认文件的键来提供国际化ui.xml文件的方法,但是必须有一种更简便的方法来实现。 That's why I tried using the ui:with tag like this to use my internationalized constants (inside the upFace): 这就是为什么我尝试使用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>

This doesn't work, the button shows the text {lang.observe} which also seems logical, but now my question is: Is there any way to use constants like this? 这是行不通的,该按钮显示的文本{lang.observe}似乎也很合理,但是现在我的问题是:有没有办法使用这样的常量? And if not could someone explain how I should use constants in UiBinder files instead (without having the compiler generate files and keys)? 如果不能,那么有人可以解释我应该如何在UiBinder文件中使用常量(而不让编译器生成文件和密钥)?

Anywhere HTML is accepted (such as within upFace ), you can use <ui:msg> , <ui:text> and <ui:safehtml> (and anywhere plain text is expected, you can use <ui:msg> and <ui:text> ). 在任何接受HTML的地方(例如upFace内),都可以使用<ui:msg><ui:text><ui:safehtml> (在任何需要纯文本的地方,都可以使用<ui:msg><ui:text> )。

So in your case: 因此,在您的情况下:

<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>

See http://www.gwtproject.org/doc/latest/DevGuideUiBinder.html#Hello_Text_Resources and http://www.gwtproject.org/doc/latest/DevGuideUiBinder.html#Hello_Html_Resources about ui:text and ui:safehtml . 有关ui:textui:safehtml请参见http://www.gwtproject.org/doc/latest/DevGuideUiBinder.html#Hello_Text_Resourceshttp://www.gwtproject.org/doc/latest/DevGuideUiBinder.html#Hello_Html_Resources

You can use constants like this : 您可以使用如下常量:

.ui.xml : .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>

and the AppResources interface : 和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();
  }
}

But for i18n you should really follow what the GWT manual says, ie there is no other (clean) way than prepare all the property files (one for each language) and generate all the required permutations. 但是对于i18n,您应该真正遵循GWT手册中的说明,即没有其他(简单的)方法是准备所有属性文件(每种语言一个)并生成所有必需的排列。 This primarily delegates to GWT all the language detection-related stuff, and the solution provided by GWT performs quite well at runtime. 这主要是将所有与语言检测相关的东西委托给GWT,GWT提供的解决方案在运行时效果很好。 The only drawback is that the compile time is a little higher (since you'll have permutations for every browser in every language you specify). 唯一的缺点是编译时间要长一些(因为您将使用指定的每种语言对每个浏览器进行排列)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM