`

gwt 国际化

    博客分类:
  • gwt
阅读更多
一般来说是这样:
  在*.gwt.xml中加入 显示中文
<inherits name="com.google.gwt.i18n.I18N"/>
<extend-property name="locale" values="zh" />这句是调用properties资源文件的!!!!
在页面中加入
<meta name="gwt:property" content="locale=zh" >




下面是国际化的过程:定义一个继承com.google.gwt.i18n.client.Messages接口的子接口MyMessages,在此接口目录下建一个名为MyMessages.properties的属性文件,可以在属性文件中定义需要国际化的字符,注意要使用UTF-8编码.定义好字符后,在MyMessages接口中定义接口方法,方法名要与属性文件中的字符相同...例如

Java代码
public interface MyMessages extends Messages {  
 
    String messageBox_ok();  
    String messageBox_cancel();  


public interface MyMessages extends Messages {

String messageBox_ok();
String messageBox_cancel();
}

对应的属性文件为:

Properties代码
messageBox_ok=确定  
messageBox_cancel=取消 

messageBox_ok=确定
messageBox_cancel=取消调用方法:

Java代码
MyMessages myMessage = GWT.create(MyMessages.class);  
myMessagees.messageBox_ok() 

MyMessages myMessage = GWT.create(MyMessages.class);
myMessagees.messageBox_ok()

以后如果需要增加多语支持,只要增加属性文件即可...



但是还可以继承Constants.properties接口,建立一个Constants_zh_CN.properties,再加上<extend-property name="locale" values="zh_CN" />即可





GWT有以下几种不同的国际化支持类,可以查看文档:

Constants
Useful for localizing typed constant values
Messages
Useful for localizing messages requiring arguments
ConstantsWithLookup
Like Constants but with extra lookup flexibility for highly data-driven applications
Dictionary
Useful when adding a GWT module to existing localized web pages
Localizable Useful for localizing algorithms encapsulated in a class
分享到:
评论
1 楼 alanlhy 2011-11-23  
正好需要,学习了,谢谢。。。

相关推荐

Global site tag (gtag.js) - Google Analytics