GWT I18N 国际化

本文是参考:http://code.google.com/intl/zh-CN/webtoolkit/doc/1.6/tutorial/i18n.html,可以参考考该文档。

上面的提示,写成中文版了。

首先:

 

  1. import com.google.gwt.i18n.client.Constants;

    public interface StockWatcherConstants extends Constants {
    @DefaultStringValue("StockWatcher")
    String stockWatcher();

    @DefaultStringValue("Symbol")
    String symbol();

    @DefaultStringValue("Price")
    String price();

    @DefaultStringValue("Change")
    String change();

    @DefaultStringValue("Remove")
    String remove();

    @DefaultStringValue("Add")
    String add();
    }

有几个字符串stockWatcher,symbol,price,change,remove,add

 

2.在StockWatcher.html写入

<meta http-equiv="content-type" content="text/html; charset=UTF-8">

 

3. StockWatcherConstants_de.properties

 

 

  1. stockWatcher = Aktienbeobachter
    symbol = Symbol
    price = Kurs
    change = Änderung
    remove = Entfernen
    add = Hinzufügen

在GWT EntryPoint继承类中写入

 private StockWatcherConstants constants = GWT.create(StockWatcherConstants.class);

     stocksFlexTable.setText(0, 3, constants.remove()
);

  1. ...
    public void onModuleLoad() {
    // Set the window title, the header text, and the Add button text.
    Window.setTitle(constants.stockWatcher());
    RootPanel.get("appTitle").add(new Label(constants.stockWatcher()));
    addStockButton = new Button(constants.add());


    // Create table for stock data.
    stocksFlexTable.setText(0, 0, constants.symbol() );
    stocksFlexTable.setText(0, 1, constants.price() );
    stocksFlexTable.setText(0, 2, constants.change() );

这们Constant常量的国际化就可以了

当然我们还要在 StockWatcher.gwt.xml写入

<extend-property name="locale" values="de"/

 

然后在地址栏中写入

 

http://localhost:8888/StockWatcher.html?locale=de

就可以了


而Messqe的话,则要传入参数

  1. public interface StockWatcherMessages extends Messages {
      @DefaultMessage("''{0}'' is not a valid symbol.")
      String invalidSymbol(String symbol);
    
      @DefaultMessage("Last update: {0,date,medium} {0,time,medium}")
      String lastUpdate(Date timestamp);
    
    }
这些值是外部类传入的。如下所示:
StockWatcherMessages_de.properties
  1. lastUpdate = Letzte Aktualisierung: {0,date,medium} {0,time,medium}
    invalidSymbol = ''{0}'' ist kein gültiges Aktiensymbol. 
在EntryPoint继承类中使用
  private StockWatcherMessages messages = GWT.create(StockWatcherMessages.class);



Window.alert(messages.invalidSymbol(symbol));

国际化介绍完毕。
 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值