JAVA国际化DEMO

2008-02-23 09:43:18来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

目录结构:
所有的文件都在包demo下.

MlLogin.Java
package demo;
import java.util.ListResourceBundle;

public class MlLogin extends ListResourceBundle
{
public MlLogin()
{
}

static final java.lang.Object[][] contents = {
{ "lblUserName", "lblUserName" },
{ "lblPassword", "lblUserName" },
{ "caseName", "lblUserName" }
};

public java.lang.Object[][] getContents() {
return contents;
}

}

ApplicationResource_zh_TW.properties
error.requiredfield=The field is required to save
label.phone=\u96fb\u8a71
label.name=\u540d\u5b57

MlLogin_zh_TW.java
package demo;
import java.util.ListResourceBundle;

public class MlLogin_zh_TW extends ListResourceBundle
{
public MlLogin_zh_TW()
{
}

static final java.lang.Object[][] contents = {
{ "lblUserName", "帳號" },
{ "lblPassword", "密碼" },
{ "caseName", "登入" }
};

public java.lang.Object[][] getContents() {
return contents;
}

}

FormatExample.java

package demo;
import java.util.ResourceBundle;
import java.util.Locale;
import java.text.MessageFormat;
/**
*
* @author limohao
*/
public class FormatExample {

/** Creates a new instance of FormatExample */
public FormatExample() {
}
public static void main(String [] args){
String ss="demo.ApplicationResource";
ResourceBundle bundle=ResourceBundle.getBundle(ss);
String requiredFieldMessage =bundle.getString("error.requiredfield");
String [] messageArgs=new String[1];
messageArgs[0]=bundle.getString("label.name");
String formatNameMessage=MessageFormat.format(requiredFieldMessage,messageArgs);
System.out.println(formatNameMessage);
messageArgs[0]=bundle.getString("label.phone");
String formatPhoneMessage=MessageFormat.format(requiredFieldMessage,messageArgs);
System.out.println(formatPhoneMessage);
try{
// Class test=Class.forName("demo.mlLogin");
// String cname=test.getName();
String cname="demo.MlLogin";
bundle=bundle.getBundle(cname);
String temp=bundle.getString("lblUserName");
System.out.println(temp);
}catch(Exception e){
e.printStackTrace();
}
}

}

Note:如果是在简体环境下测试可将zh_TW改为zn_CN

上一篇: Jsp JavaBean循序渐进教程(四)
下一篇: Jsp JavaBean循序渐进教程(六)

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:J2EE编程起步(一)

下一篇:J2EE编程起步(二)